2.4 Linked List Implementation in C/C++ | Creation and Display | DSA Tutorials
Вставка
- Опубліковано 1 жов 2024
- Jennys Lectures DSA with Java Course Enrollment link: www.jennyslect...
******************************************
CORRECTION: @24:10 initialize choice variable with 1 by writing:
int choice=1;
******************************************
In this video we will see implementation of basic operations like Create a Node in Linked List and traverse a Linked List.
DSA Full Course: https: • Data Structures and Al...
******************************************
See Complete Playlists:
C Programming Course: • Programming in C
C++ Programming: • C++ Complete Course
Python Full Course: • Python - Basic to Advance
Printing Pattern in C: • Printing Pattern Progr...
DAA Course: • Design and Analysis of...
Placement Series: • Placements Series
Dynamic Programming: • Dynamic Programming
Operating Systems: // • Operating Systems
DBMS: • DBMS (Database Managem...
************************************************
Connect & Contact Me:
Facebook: / jennys-lectures-csit-n...
Quora: www.quora.com/...
Instagram: / jayantikhatrilamba
#linkedlist #datastructures #algorithms
CORRECTION: @24:10 initialize choice variable with 1 by writing:
int choice=1;
long time no see
@@kangmoabel still she is the best
the way she teaches,, its unique & efficient enough..
After loop which is one printed for creating list
Mam can u please provide printed code ?....plzz
@@Mohammed.1471
@SB_Roy_Vlogs
#include
#include
#include
struct node{
int data;
struct node *next;
};
int main(){
struct node *head,*newnode,*temp;
int choice=1;
head=NULL;
while(choice){
newnode=(struct node*)malloc(sizeof(struct node));
printf("Enter node:");
scanf("%d",&newnode->data);
newnode->next=NULL;
if(head==NULL){
head=newnode;
temp=newnode;
}
else{
temp->next=newnode;
temp=newnode;
}
printf("Enter 1 for continue and 0 for exit:");
scanf("%d",&choice);
}
temp=head;
while(temp!=NULL){
printf("%d->",temp->data);
temp=temp->next;
}
printf("NULL");
getch();
return 0;
}
Oh my, why can’t i understand anything 😢
Did you get then?
Did you pass the course?
😂😂
@@learnersacademybyhaya.345it's been 1 year 😲 , luckily I passed my exam(data structure), it was my 3rd sem subject and currently I am on my final sem(time files like a jet)
@@learnersacademybyhaya.345 yeh, I passed luckily anyway🥹. It was one of my 3rd sem subject
I am also😢😢😢😢
At this point, I dropped my college classes to watch your videos. I learn so fast with you, even though english is not my first language. A big thank you from Brazil!
mi amor brasilia
Bro
@@replyingtomemeansyourstupi8996 iam stupid
Great
Which study you were doing which course
/*Creation and display of singly linked list*/
#include
#include
#include
void main()
{
struct node{
int data;
struct node *next;
};
struct node *head,*newnode,*temp;
head=0;
int choice;
while(choice){
newnode=(struct node*)malloc(sizeof(struct node));
printf("enter data");
scanf("%d",&newnode->data);
newnode->next=0;
if(head==0)
{
head=temp=newnode;
}
else
{
temp->next = newnode;
temp=newnode;
}
printf("do you want to continue");
scanf("%d",&choice);
}
temp=head;
while(temp!=0)
{
printf("%d",temp->data);
temp=temp->next;
}
}
this code will node work because you have to assign your choice=1 before while
#include
#include
int main(){
struct node{
int data;
struct node * next;
};
struct node *head, *newnode , *temp;
head = 0;
int choice = 1;
while(choice){
newnode =(struct node *)malloc(sizeof(struct node));
printf("Enter data");
scanf("%d", &newnode -> data);
newnode->next = 0;
if(head == 0){
head = temp = newnode;
}
else{
temp -> next = newnode;
temp = newnode;
}
printf("Do you want to continue (0 , 1)?");
scanf("%d",&choice);
}
temp = head;
while(temp != 0)
{
printf("%d",temp-> data);
temp = temp -> next;
}
}
this helped a lot to me thank you
So clean bro.
hai kis chees ka
Her dedication should be really appreciated.Please do all algorithms then leetcode also. She will be a youtube education trainer star. Her videos are being viewed from all corners of the world. in short she is helping many students who lack proper lectures. Some people born to help and a bring change in world. She has long way to go.
Please explain me what is the difference between head pointer and newnode pointer and why malloc is used for only newnode but not head
@@badrip3237 the declaration "struct Node* head = NULL" reserves memory for the pointer variable 'head', it doesn't allocate memory for the 'node' structure itself at this point. the memory for the Node structure is dynamically allocated using the malloc.
One of the best DS lectures i have ever seen on youtube. The tricky concept of linked list has been explained in such an interactive and crystal clear manner that i was able to think of the codes of other operations on singly linked list by end of video.
This type of content deserves millions of views. Wish you get 1 Million + subs soon.
Thanks for the awosome content.
Respect from NIT Jalandhar
Ma'am I have seen many videos of data structures but yours is best 💯thanks a lot for such a best explaination of the concept🙌👍
Mam ne wakai accha tarike se samjhaya hai
Your words are really true bro...
@@pundlikpatil2380 bhai printf scanf ki jgh cout cin ka he to diff hai itna kuch nhi hai same he to hai bro
Kitna paisa mila yeh sab likhne ke liye Bhai
Thank you ma'am.
The code taught by ma'am is :
#include
#include
void main(){
struct node{
int data;
struct node *next;
};
struct node *head;
struct node *newnode;
struct node *temp;
head=NULL;
int choice,count=0;
while(choice)
{
newnode=(struct node*)malloc(sizeof(struct node));
printf("Enter Data:
");
scanf("%d",&newnode->data);
newnode->next=0;
if(head==0)
{head=temp=newnode;}
else
{
temp->next=newnode;
temp=newnode;}
printf("Do you want to continue (0,1)?
");
scanf("%d",&choice);
}
printf("--------------------------------
");
temp=head;
while(temp!=0)
{
printf("
%d
",temp->data);
temp=temp->next;
count++;}
{
printf("
Count=%d",count);}
}
thanks
Appreciate it bro
Thanks brother
🔥💥
Doesn't run proberly
You're exuberantly flawless miss Jenny!! Thanks a lot ❤
CODE :
#include
#include
int main()
{
struct node{
int data ;
struct node*next;
};
int choice =1;
struct node*head;
struct node*temp;
struct node*newNode;
head=0;
while(choice){
newNode = (struct node*) malloc(sizeof(struct node));
printf(" enter the data ");
scanf("%d",&newNode->data);
newNode->next=0;
if (head==0)
{
head= temp=newNode;
}
else {
temp->next=newNode ;
temp= newNode;
}
printf ( " do u want to continue ( type 0 or 1)?
");
fflush(stdin);
scanf("%d",&choice);
}
temp= head;
printf("items in linked list are:");
while(temp!=0)
{
printf( " %d",temp->data);
temp= temp->next;
}
return 0;
}
thank you mam
tqsm yar...
Thanks a lot brother❤
Because of you I am alive ... Can't understand a single concept in my clg but after your 30 mins lecture ... Its now clear and understandable ... Proper explanations and best tutorials in UA-cam for CS students ... Keep this amazing work up !!
#include
#include
struct node{
int data;
struct node*next;
};
int main(){
struct node *head,*newnode,*temp;
head=0;
int choice=1;
while(choice){
newnode=(struct node*)malloc(sizeof(struct node ));
printf("enter the data that you want to insert in linked list = ");
scanf("%d",&newnode->data);
newnode->next=0;
if(head==0){
head=temp=newnode;
}
else{
temp->next=newnode;
temp=newnode;
}
printf("do you want to continue (1 for yes and 0 for No) = ");
scanf("%d",&choice);
}
temp=head;
printf("the list is =");
while(temp!=0){
printf(" %d",temp->data);
temp=temp->next;
}
}
Everything was going well before this video but this video made me realize that i am still noob😥😥
Madam can you excute in the system plz
Thank u so much Maam, the lecture was one of the effective and understanding DS lectures I had watched since now. I again Thank u for the effort you have taken for providing us this Wonderful Lecture.
Mam
I am crazy about you.....
I fell in love the minute i saw you 😍
Mujse shadhi karogi
I have a doubt mam. Only when head ==0 , we are setting temp = new node. When head is not 0, we are not assigning anything to temp and we are assigning temp-> next = new node, here what is temp->next ?? As we are not assigning anything to temp?
Clarify my doubt, mam
Thank you 😊
You have given new life to my understanding of the C program Link List.
you explain so good, there is not a lot of QUALITY videos regarding linked list, you are among the few I have ever seen, you made me understand linked list (which I am doing in C now) and I managed to success my homework after trying it for a week without success, you are amazing, I want to thank you for that!
These videos are only for C programming and not for c++.
This is like exponential times better than my phd professor , glad to be learning from this !
Hi mam
Here in the last while condition
Is it
While(temp != 0) ? Or
While (temp->next != 0) ?
I have to ignore mam in video to understand the topic
Why she 's so beautifull❤
#Full code herre thanks mam..
#include
#include
#include
struct node{
int data;
struct node *next;
};
int main(){
struct node *head,*newnode,*temp;
int choice=1;
head=NULL;
while(choice){
newnode=(struct node*)malloc(sizeof(struct node));
printf("Enter node:");
scanf("%d",&newnode->data);
newnode->next=NULL;
if(head==NULL){
head=newnode;
temp=newnode;
}
else{
temp->next=newnode;
temp=newnode;
}
printf("Enter 1 for continue and 0 for exit:");
scanf("%d",&choice);
}
temp=head;
while(temp!=NULL){
printf("%d->",temp->data);
temp=temp->next;
}
printf("NULL");
getch();
return 0;
}
One of the best teacher I have ever seen in my life who explained linked list in such an easy way.
Thanks mam for uploading this video.
Mam , why you are not doing coding part in software,it will be easier 4 us.just create one coding session and provide a link in each linked video
I was so tensed with linked list.Tried paid courses,even watch other so called 80 k+ subscriber's channels no one was better than you.u explain from heart not juzz for subscribers.hoping 4ur 1 Million+ n ahead!!!! Tysm ma'am
One of the best video on linked list. I tried to learn from different sources but coudn't understand. But after watching this video my concepts are completely clear. The concept has been explained in crystal clear manner. Thank you so much ma'am for this awesome video.
when printing if I write just temp in the condition it appears an error, if I write temp->next in the condition and then I print before moving temp->next it doesn't print the last one as it is equal to cero and if I move temp->next first and then print, it doesn't print the first one.... 🤔
Ma'am you are so beautiful so I can't focused 😭😭
why are we not declaring struct node*newnode,*temp etc inside struct node datatype??
#include
#include
struct list
{
int data;
struct list *next;
};
typedef struct list list;
list *head , *start , *temp;
void main()
{
head = 0;
int a;
int count = 0;
do
{
count++;
start = (list*)malloc(sizeof (list));
printf("Enter Data : ");
scanf("%d",&start->data);
start->next=0;
if (head == 0)
{
head = temp = start;
}
else
{
temp->next=start;
temp=start;
}
printf("
Press 1 To Continue Adding More Data Or 0 To End [ 1 / 0]
");
scanf("%d",&a);
} while (a);
int i=1;
printf("
No of data added = %d
",count);
temp = head;
while (temp != 0)
{
printf("
%d. Data is = %d
",i++,temp->data);
temp = temp->next;
}
}
A big round of applause from Pakistan. Great work....
But please do the same in Java coding. Thank you
review time: guys lectures are worth it ( you don't need review i know it, but i have to brag my grades as well lol!! ) i got an A both in thoery and lab.. so you can do it...
Jenny mam your teaching skills are way better than tier 1 2 3 college teachers really grateful to consume such valuable content for free hats of to your hard work and dedication towards Teaching, every engineers programming base is created from UA-cam .... :)
Maam's code is below this
#include
#include
void main()
{
struct node{
int data;
struct node* next;
};
struct node* newnode,*head, *temp;
int choice=1,count=0;
head=NULL;
while(choice==1){
newnode=(struct node*)malloc(sizeof(struct node));
printf("Enter Data:
");
scanf("%d",&newnode->data);
newnode->next=0;
if(head==0)
{
head=temp=newnode;
}
else{
temp->next=newnode;
temp=newnode;
}
printf("DO you wish to continue:1 for yes and 0 for no
");
scanf("%d",&choice);}
printf("-----------------------
");
temp=head;
while(temp!=0)
{
printf("%d
",temp->data);
temp=temp->next;
count++;
}
printf("%d",count);
}
Really mam the lecture was soo understanding, i was having soo much difficulty in implementation of link list but nothing helped me out.Your lecture was soo good and excellent that i have no doubts remained please continue to teach us like this mam.Really you're a fabolous teacher
Hey! Videos are really of great help. I very much appreciate the content and dedication.
This explanation can be bit better as in the traversal of temp pointer could have been explained little more.
Seriously she deserves Oscar in teaching profession ❤
#include
void main() {
struct node {
int data;
struct node *next;
};
struct node *head, *newnode, *temp;
head=0;
int choice=1;
while (choice) {
newnode=(struct node *)malloc(sizeof(struct node));
printf("
Enter data: ");
scanf("%d", &newnode->data);
newnode->next=0;
if (head==0) {
head=temp=newnode;
}
else {
temp->next=newnode;
temp=newnode;
}
printf("Do you want to continue? (0/1): ");
scanf("%d", &choice);
}
temp=head;
while (temp!=0) {
printf("%d ", temp->data);
temp=temp->next;
}
getch();
}
w o w she's smart, well-spoken and gorgeous?? My brain has officially broken!
Thanks mam for teaching in such an amazing way , keep giving your valuable knowledge 🤩🤩🤩🔥🔥🔥
can you make videos in c++
Ma'am its my 17th time of watching this video though I haven't understood this concept well but Dekhna Acha Lagta hai
Who the hell has said the one way communication can't work...🙄
This is incredible mam thanku🥺🌝💗💗
I am still confused in this linked list impletation
Amazing, you didn't only explain the concept of linked lists well, you also taught how to think and construct the program along the way, adding the if else , while loops . Wish I had someone teach me concept like this 10 us back when I graduated I would have found greater joy and purpose in life with programming.
GeeksforGeeks is organising mini course of DSA that you should not miss out.
Why??
1. Live QnA sessions, you can clear all doubts related to DSA. Any doubt from LinkedList to Graph.
2. You will get practice problems after every Data structure to make you good at DSA and crystal clear concepts.
3. After completion of course you will get certificate and can access course anytime.
4. Its FREE!!! But only if you use the below code -
GFGD4Y2JR
Register here-
practice.geeksforgeeks.org/courses/Workshop-DSA?loginMode=308
Best lecture ever ma'am...u have explained every single point...
You can't imagine how much you are helping some of us
I finally understood the concept of linked list.
previously, I watched thousands of other youtubers, teaching the same thing and no body does it better than you .
Thank you so much mam.....
I had lots of confusion .. but now I understand everything about linked list...thank you so much Jenny mam..
Students like us ..who do not understand concepts easily you teach us easily.😊
Initialise for loop for creating multiple number of linked list
A big thanks to you ma'am,i was so frustrated on this topic but you clear all my confusion and make a clear cut concept, thanks you.❤️🤘
GeeksforGeeks is organising mini course of DSA that you should not miss out.
Why??
1. Live QnA sessions, you can clear all doubts related to DSA. Any doubt from LinkedList to Graph.
2. You will get practice problems after every Data structure to make you good at DSA and crystal clear concepts.
3. After completion of course you will get certificate and can access course anytime.
4. Its FREE!!! But only if you use the below code -
GFGD4Y2JR
Register here-
practice.geeksforgeeks.org/courses/Workshop-DSA?loginMode=308
#include
#include
struct node{ //own data type
int data; //4 bytes
struct node *next; //4 bytes
//struct node is data type of node, whose add next will store
};
void main()
{
printf("hello world
");
struct node *head, *new_node, *temp; //struct node is data type of node, whose add head will store
head=0;
int choice, count=0;
//dynamic allocation - malloc function
while(choice){
new_node=(struct node*)malloc(sizeof(struct node)); //8 bytes is allocated dynamically
printf("enter the data:
");
scanf("%d", &new_node->data);
new_node->next=0; //null
if(head == 0){
head= temp=new_node;
}
else {
temp->next= new_node;
temp=new_node;
}
printf("do you want to continue(0,1)?");
scanf("%d", &choice);
}//while
temp=head;
printf("All the linkedlist data :
");
while(temp!=0){ //to print the data of linked list
printf("%d
", temp->data);
temp= temp->next;
count++;
}//while
printf("count : %d", count);
getch();
}
o....mother of algorithm...💚💛🧡
i never seen such like explanation. ..only and only requist capture ever topic. .
You teach Link List completely in a very logical way and i hope you will never remove this taturail or never chang to payment site . thank you.... wish you the best .
GeeksforGeeks is organising mini course of DSA that you should not miss out.
Why??
1. Live QnA sessions, you can clear all doubts related to DSA. Any doubt from LinkedList to Graph.
2. You will get practice problems after every Data structure to make you good at DSA and crystal clear concepts.
3. After completion of course you will get certificate and can access course anytime.
4. Its FREE!!! But only if you use the below code -
GFGD4Y2JR
Register here-
practice.geeksforgeeks.org/courses/Workshop-DSA?loginMode=308
the value of the choice variable must be set to 1 for the initial entry into while loop, EXCELLENT LECTURE MAM !! A great tutorial that took me to the basics !!! happy_coding_geeks !!
Implemented correct code from my side :
//linked list
#include
#include
int main(){
struct node{
int data;
struct node *next;
};
int choise = 1,count = 0;
struct node *newnode, *temp, *head = 0;
while(choise){
newnode = (struct node*)malloc(sizeof(struct node));
printf("
Enter the data ");
scanf("%d",&newnode->data);
newnode->next = 0;
if(head == 0){
head = temp = newnode;
}else{
temp->next= newnode;
temp = newnode;
}
printf("
Enter the choise : ");
scanf("%d",&choise);
}
printf("
Our data is : ");
temp = head;
while(temp!=0){
printf("
Data : %d",temp->data);
temp = temp->next;
}
}
Mam the printing part of the code will run infinitely
Beacause it was set to run untill temp becomes '0' i.e. the address stored in last node
But the next part of last node contains a garbage value by default. So we have to manually put temp=0 in the last iteration i.e. when last node is created
Miss, i have been trying to learn linked list for last 4/5 days.. And wasted 6/7 hours. But somehow i found your video and thought 30 mins will waste again.. But everything changed when you were explain.. You made it so clear and easy.. Thanx for the great video..
The same here...bro....😉😉😉
Traversal is not working please help
I would like to owe you my genuine respect from the core of my heart....a huge amount of respect from me....n fr my friends from Vellore institute of Technology....
Actual code what mam told is:
#include
#include
void main()
{
struct node
{
int data;
struct node *next;
};
struct node *head,*newnode,*temp;
head=NULL;
int choice=1;
while(choice)
{
newnode=(struct
node*)malloc(sizeof(struct node));
printf("Enter Data:");
scanf("%d",&newnode->data);
newnode->next=0;
if(head==0)
{
head=temp=newnode;
}
else
{
temp->next=newnode;
temp=newnode;
}
printf("Do you want to continue (0,1)?
");
scanf("%d",&choice);
}
temp=head;
while(temp)
{
printf("%d",temp->data);
temp=temp->next;
}
}
Thankyou mam i pass the data structure exam by watching your videos😊❤.its really very very helpfull to me
What's the problem in my code I m not getting required output:-
#include
#include
struct node
{
int data;
struct node *next;
}*head=NULL,*newnode,*temp;
int main()
{
int count;
int choice=1;
while(choice)
{
newnode=(struct node*)malloc(sizeof(struct node));
printf("Enter the data item:");
scanf("%d ",&newnode->data);
newnode->next=NULL;
if(head==NULL)
{
head=temp=newnode;
}
else
{
temp->next=newnode;
temp=newnode;
}
printf("Do you want to continue(0,1) ?
");
scanf("%d",&choice);
}
temp=head;
while(temp!=NULL)
{
printf("%d ",temp->data);
temp=temp->next;
count++;
}
printf("%d",count);
return 0;
}
This lecture is so good.. I can't thnk you enough for the lectures u provide.. solid lecture 💯💯
Mam I'm really thankful for you ❤️. I never thought that I would understand this topic but you made this really easy to understand. This society needs more teachers like you. Thank you for your amazing help mam💜
I can't run it with while(choice), I am using Do-while instead...is that correct way to approach?
with do whille it will be executed once and the ask which doesn't affect anything in short it doesn't matter
shuru mai bhi jab ham choice declare kar rhe hai tih bhi shayad choice ki value deni padegi like int choice=1;
Can you please give me the full code?
I am also struggling to run it
Please make this video in c++ only, because it is creating problem for me.i Will be very thankful to you.
Please, please please.
Hello from the USA. Thank you for making these videos mam! I found your channel last spring as I was struggling to implement a linked list ds for a masters course. I found your channel and after watching this video everything clicked for me and I totally understood what I needed to do. I've since passed my course but I find myself still watching videos on your channel even though I don't need to for any course work bc I find your teaching style and white board approach to be so effective.
Sir ,in usa how is the scope of IT sector ? Is it has much scope?
hello mam......a small request mam....>>>>>>>>.please revise all the concept of a video at last mam...so that we can easily understand😇
one of the best DS lectures i have ever seen on youtube....
this type of lecture is not present on youtube..thanks mam
Ma'am I have a doubt ,I have an error in if(head=newnode->next=0)
It seems Id returned 1 exit status.
Can anyone send me the copy of code in c on the editor ...please
Thank you teacher.
after 4 days of wandering here and there , its all clear now .
Edo Malayalam movie ni Telugu subtitles tho chusthunattu undi 😭
Ardam aitunda bro?
@@KHAN-dg2qs ardam kavatledu bro
@@dhanushponnada-hl9kw Sandeep Saradhi Ani Search chey bro , manchi explanation untadi akkada
@@KHAN-dg2qs can't understand anything 😔😔😔
Awesome linked list tutorial thank you.
It's my request, if you can make video on some higher competitive problems like baktracking,highest substring palindrome pls make
Thanks🙏🙇
To display our list what should we write in code???(for c language)
#include
#include
Int main()
struct node
{
Int data;
struct node*link;
}
Struct node *head,*newnode;
Newnode=(struct node*)malloc(size of(struct node))
printf("enter data to insert");
Scanf("%d",&data);
Newnode ->link = head;
Head=newnode;
?????
Yaha per hamne newnode join krdiye at beginning but now, how should i display the whole list after this upgradation??? Iske aage ka code batao mam ek baar , program khatam kaise karein?? getch() kab use karna hai us list ko display kaise karna hai???
#include
#include
For c language
And
#include
For c++
Getch ( ) user se input lene k liye krna he use like cin in c++ and scanf in c language
I hope you get it.
Ma’am I’m getting conflicting types for head, while declaring head=0
Sorry, but head ache lecture not clean as previous lecture and plz explain in pure not little English.
Mam my cousin became your fan at first sight.He listens your lec by sitting with me even though he is not studying at all.
🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣suma eru da
Thanks a lot madam. I was struggling with these for 1 week. I couldn't find any proper material or any lecture video or notes containing good explanations. But after seeing your lecture I am really feeling very comfortable with the topic. Thank you very much for such great explanation. 😊😊
Bhai ye program run hua tha
Can I alone like and subscribe a million times?
what a explanation, you just won my heart. I got this lecture after suffering a lot from linked list. Thank you so much MAM for providing such a wonderful lecture.
Nothing was added in the list
Recently started following your channel.
Good stuff on data structure and algorithms.
Almost everything is covered and explained clearly.
Being a non CS student it is difficult to understand DS but you have made it easy. Thank you.
Ma'am hindi me series start kro na c++ or dsa ki English thoda confusion create krta he isiliye ❤
...been struggling with this for quite some time. Thank you for the help!
Mam aap ke programming me 4 places par error aarahe h please help
Man now all clear but I have problem in output
Proper explanation!Amazing lecturer...Each and every point was explained briefly and she cleared almost all my doubts and confusions regarding link list within minutes.Thank you for this.😊
Mam one doubt agar hum first node insert krwa rhe hai in linked list too uss first node ko memory mai starting mai null mill skta hai kya
PLEASE CAN YOU GIVE THIS CODE IN C++
#include
#include
#include
using namespace std;
struct node{
int data;
node *next;
};
int count=0;
node *head=0,*newnode,*temp;
class linked{
public:
void createnode();
void traverse();
};
int main(){
int choice;
char ch;
linked li;
do{
cout
Brother can I give code for c I'm unable be execute above code I'm getting errors
@@shonemicheal4935 Can you please provide the complete code of Linked List in C ?
@@mavericks5763 idk c bro
@@mavericks5763 #include
#include
struct node
{
int data;
struct node *next;
};
struct node *head;
void beginsert ();
void lastinsert ();
void randominsert();
void begin_delete();
void last_delete();
void random_delete();
void display();
void search();
void main ()
{
int choice =0;
while(choice != 9)
{
printf("
*********Main Menu*********
");
printf("
Choose one option from the following list ...
");
printf("
===============================================
");
printf("
1.Insert in begining
2.Insert at last
3.Insert at any random location
4.Delete from Beginning
5.Delete from last
6.Delete node after specified location
7.Search for an element
8.Show
9.Exit
");
printf("
Enter your choice?
");
scanf("
%d",&choice);
switch(choice)
{
case 1:
beginsert();
break;
case 2:
lastinsert();
break;
case 3:
randominsert();
break;
case 4:
begin_delete();
break;
case 5:
last_delete();
break;
case 6:
random_delete();
break;
case 7:
search();
break;
case 8:
display();
break;
case 9:
exit(0);
break;
default:
printf("Please enter valid choice..");
}
}
}
void beginsert()
{
struct node *ptr;
int item;
ptr = (struct node *) malloc(sizeof(struct node *));
if(ptr == NULL)
{
printf("
OVERFLOW");
}
else
{
printf("
Enter value
");
scanf("%d",&item);
ptr->data = item;
ptr->next = head;
head = ptr;
printf("
Node inserted");
}
}
void lastinsert()
{
struct node *ptr,*temp;
int item;
ptr = (struct node*)malloc(sizeof(struct node));
if(ptr == NULL)
{
printf("
OVERFLOW");
}
else
{
printf("
Enter value?
");
scanf("%d",&item);
ptr->data = item;
if(head == NULL)
{
ptr -> next = NULL;
head = ptr;
printf("
Node inserted");
}
else
{
temp = head;
while (temp -> next != NULL)
{
temp = temp -> next;
}
temp->next = ptr;
ptr->next = NULL;
printf("
Node inserted");
}
}
}
void randominsert()
{
int i,loc,item;
struct node *ptr, *temp;
ptr = (struct node *) malloc (sizeof(struct node));
if(ptr == NULL)
{
printf("
OVERFLOW");
}
else
{
printf("
Enter element value");
scanf("%d",&item);
ptr->data = item;
printf("
Enter the location after which you want to insert ");
scanf("
%d",&loc);
temp=head;
for(i=0;inext;
if(temp == NULL)
{
printf("
can't insert
");
return;
}
}
ptr ->next = temp ->next;
temp ->next = ptr;
printf("
Node inserted");
}
}
void begin_delete()
{
struct node *ptr;
if(head == NULL)
{
printf("
List is empty
");
}
else
{
ptr = head;
head = ptr->next;
free(ptr);
printf("
Node deleted from the begining ...
");
}
}
void last_delete()
{
struct node *ptr,*ptr1;
if(head == NULL)
{
printf("
list is empty");
}
else if(head -> next == NULL)
{
head = NULL;
free(head);
printf("
Only node of the list deleted ...
");
}
else
{
ptr = head;
while(ptr->next != NULL)
{
ptr1 = ptr;
ptr = ptr ->next;
}
ptr1->next = NULL;
free(ptr);
printf("
Deleted Node from the last ...
");
}
}
void random_delete()
{
struct node *ptr,*ptr1;
int loc,i;
printf("
Enter the location of the node after which you want to perform deletion
");
scanf("%d",&loc);
ptr=head;
for(i=0;inext;
if(ptr == NULL)
{
printf("
Can't delete");
return;
}
}
ptr1 ->next = ptr ->next;
free(ptr);
printf("
Deleted node %d ",loc+1);
}
void search()
{
struct node *ptr;
int item,i=0,flag;
ptr = head;
if(ptr == NULL)
{
printf("
Empty List
");
}
else
{
printf("
Enter item which you want to search?
");
scanf("%d",&item);
while (ptr!=NULL)
{
if(ptr->data == item)
{
printf("item found at location %d ",i+1);
flag=0;
}
else
{
flag=1;
}
i++;
ptr = ptr -> next;
}
if(flag==1)
{
printf("Item not found
");
}
}
}
void display()
{
struct node *ptr;
ptr = head;
if(ptr == NULL)
{
printf("Nothing to print");
}
else
{
printf("
printing values . . . . .
");
while (ptr!=NULL)
{
printf("
%d",ptr->data);
ptr = ptr -> next;
}
}
}
Disappoint to implement C, every one use C but not C++.
Even 1million likes are less for this lecture!!
mam please skeak in hindi i can understand english but in hindi its easy to lean fast
Your videos are very helpful during this lockdown period.
Thank You ❤
Please Mam Make A Playlist For Java .....Your Teaching Style Is So So..........Good..Please Mama I Want To Learn Java From You......Please Mam .... Who Want This Please Support
Thnk yu...
BTW How yu said "fine" in last is funny nd cute.
Mam, in first loop while (choice) we enter the value in the last so how can first time program work.
yeah it must be int choice=1; then it will work
can anyone show me the complete linked list program..in same way she is teaching..same variables,functions,and datatypes
Veer Beniwal can you send me too, if someone sent you?
#include
#include
int main()
{
struct node
{
int data;
struct node *next;
};
typedef struct node NODE;
int choice=1;
NODE *head,*newnode,*temp;
head=0;
while(choice)
{
newnode=(NODE *)malloc(sizeof(NODE));
printf("Enter data item
");
scanf("%d",&newnode-> data);
newnode->next=0;
if(head==0)
{
head=temp=newnode;
}
else
{
temp->next=newnode;
temp=newnode;
}
printf("Do you want to continue:(Type 0 or 1)?
");
fflush(stdin);
scanf("%d",&choice);
}
temp=head;
printf("Linked list items: ");
while(temp!=0)
{
printf("%d ",temp->data);
temp=temp->next;
}
return 0;
}
@@aniketmishra8197 Correct, I was thinking that how will it go in while loop already but you have declared choice that is right and instead we can also use do while also , do while will also do right?
bro i have an doubt, y we using NODE.
@@fahimsharuk433 to avoid writing struct node.
You can take snap at 27.54