Introduction to Linked List | C++ Placement Course | Lecture 22

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Jisko pehle se aata hain uske liye to best hain bahut new chj pta chala thankyou didi 😍

swapnilsrivastava
Автор

best video
ab mujhe clear ho gya ki mujhe coding me nhi jana...🙂

lifeology
Автор

Perfect example of everyone with knowledge is not a good teacher....

KrishnaSharma-bvys
Автор

Full Code Of This Video

#include<iostream>
#include<bits/stdc++.h>
using namespace std;

// Create A class node

class node{
public:
int data;
node* next;

// Node Class Constructor
node(int val){
data=val;
next=NULL;

}
};

// Insert Element At Tail

void insertAtTail(node* &head, int val){
node* n=new node(val);
if(head==NULL){
head=n;
return;
}
node* temp=head;
while(temp->next!=NULL){
temp=temp->next;
}
temp->next=n;
}

// Display All Element

void display(node* head){
node* temp=head;
while(temp!=NULL){
cout<<temp->data<<"->";
temp=temp->next;
}
cout<<"NULL"<<endl;
}

// Insert At Head

void insertAtHead(node* &head, int val){
node* n=new node(val);
n->next=head;
head=n;
}

// Seraching At Linked List

bool Search(node* head, int key){
node* temp=head;
while(temp->next!=NULL){
if(temp->data==key){
return true;
}
temp=temp->next;
}
return false;
}

int main(){

node* head =NULL;
insertAtTail(head, 12);
insertAtTail(head, 178);
insertAtTail(head, 1788);
display(head);
insertAtHead(head, 345);
display(head);
cout<<Search(head, 178);

return 0;
}


Output-
12->178->1788->NULL
345->12->178->1788->NULL
1

siddharthabhunia
Автор

Kuchh Samajh Nahi Aaaya...Par Sunke Achha Lagaaaa :)

biswaranjandash
Автор

And that's where difficulty start and competition drops !!

aryarajput
Автор

Guy's in case you don't understand this topic
Keep in mind we are first making a node and then linked them by address of other nodes and initially head is null but in further calls head has address of first node and only temp changes it's address i.e it store address of node from which we link it to other

ShubhamKumar-pvpj
Автор

****Creating single
# include<iostream>
using namespace std;
class Node
{
public:
int data;
Node* next;
Node(int data)//creating constructor to fill data in node
{
this->data = data;
this->next = NULL;
}
};


int main()
{
Node* node1 = new Node(10);//creating object node1 of node class and allocating dynamic memory to it
cout << node1->data << endl;//printing data
cout << node1->next << endl;



return 0;

}
Link at
# include<iostream>
using namespace std;
class Node
{
public:
int data;
Node* next;//next is a pointer to a node structure, and indicates the next item in the list
Node(int data)//creating constructor to fill data in node
{
this->data = data;
this->next = NULL;
}
};
void insertAtHead(Node* &head, int d)//here done by referance
{
Node* temp = new Node(d);//creating a pointer temp of Node class and allocating dynamic memory and also creating Node with value d
temp->next = head;//assigning temp's next to head of node1
head = temp;//shifting head position from node1 to temp
}
void print(Node* &head)
{
Node* sk = head;//here i have passed by referance and i dont want ot change value of head so i created another pointer of name "sk".
while (sk != NULL)
{
cout <<sk->data << " ";//print temp data

sk = sk->next;//moving sk position from temp to second node
}
cout << endl;
}
int main()
{
Node* node1 = new Node(10);//creating pointer node1 of Node class and allocating dynamic memory to it and also create node with data 10
Node* head = node1;//creating head pointer and pointing where node1 pointer is pointing

insertAtHead(head, 12);// passing data of element which is to be inserted
print(head);



return 0;

}
****adding node at end****
# include<iostream>
using namespace std;
class Node
{
public:
int data;
Node* next;//next is a pointer to a node structure, and indicates the next item in the list
Node(int data)//creating constructor to fill data in node
{
this->data = data;
this->next = NULL;
}
};
void insertAtHead(Node* &head, int d)//here done by referance
{
Node* temp = new Node(d);//creating a pointer temp of Node class and allocating dynamic memory and also creating Node with value d
temp->next = head;//assigning temp's next to head of node1
head = temp;//shifting head position from node1 to temp
}
void print(Node* &head)
{
Node* sk = head;//here i have passed by referance and i dont want ot change value of head so i created another pointer of name "sk".
while (sk != NULL)
{
cout <<sk->data << " ";//print temp data

sk = sk->next;//moving sk position from temp to second node
}
cout << endl;
}
void insertattail(Node* &head, int d)
{
Node* tail;//creating new pointer with name tail
tail = head;//pointing tail pointer to loaction of head
while (tail->next != NULL)
{
tail = tail->next;//finding the last position of linked list
}

tail->next = new Node(d);//adding element to the linked list
}
int main()
{ Node* node1 = new Node(10);//creating pointer node1 of Node class and allocating dynamic memory to it and also create node with data 10
Node* head = node1;//creating head pointer and pointing where node1 pointer is pointing
insertAtHead(head, 12);// passing data of element which is to be inserted
insertattail(head, 4354);
insertattail(head, 234);
insertattail(head, 21);
print(head);
return 0;

}

SJ-qrqp
Автор

Starting be like: Array mein size hota hai, Array accha nahi hai, Array is fixed, Link list has more advantages
End: Isse accha toh array hi bana leta....

shubham.s
Автор

Is this introduction for iit bombay STUDENTS..?
i think they can't understand this introduction

piyushgupta
Автор

From this video difficulty increases and our competition drops🤭

ayushkamboj
Автор

I think this video is meant for her own revision 😑

rakesh
Автор

Not very good explanation for a beginner... No offence but it could have been better.
Thank u for this series

SARTHAK_K._PATRO
Автор

Very good explanation of linked list. 😊

Why to use LL ?
When we want to add or remove elements very often and little need to traverse or search elements.
Example: stack and queue

-> we are using pointer of Node instead of class node.
Node * n = new Node(0)

-> & before variable on method parameter represent reference by location.
If we don’t want to use & then we need to return head node of LL.

Node * Insert( Node * head )
{ ... }

Happy learning 😊

rutvikrana
Автор

this is literally superb !!! I was having error writing the code, and few channels only covered only the concept part and left the code . the other problem was most channels have used malloc fn .I skipped c lang and was having trouble to write the code in cpp using new. Thanku so much

dhairyshrivastava
Автор

this series is not up to the mark bro
very difficult for begginers to understand
no use of animation
cant understand a thing
i have started to use it as a referance to what to study next and nothing more

iamdj
Автор

What will we do with animations when most of us cant understand any thing??? this is what you call the best course??

nazibuddin
Автор

I can't understand anything, but i am trying to understand that😂

rahulkumarsingh
Автор

Osmm mam... What an explanation..meko bht achchhe se smjh aya 😊

gauravroy
Автор

thank you its really good explanation its fast paced but still helpful don't see other comments its just not meant for begineer they cant comprehend to it

mohitparker