lnishan / awesome-competitive-programming

:gem: A curated list of awesome Competitive Programming, Algorithm and Data Structure resources
http://codeforces.com/blog/entry/23054
Creative Commons Attribution 4.0 International
12.36k stars 2.56k forks source link

Create Create a Linked List #107

Closed KRITGYA2001 closed 3 years ago

KRITGYA2001 commented 3 years ago

include

include

struct node { int data; struct node next; }start,save,ptr;

int main() { start=NULL; char ch='y';

while(ch=='Y' || ch=='y') { ptr = (struct node *)malloc(sizeof(struct node)); printf(" Input the value in the nodes : "); scanf(" %d", &ptr->data); ptr->next=NULL; if(start==NULL) { start=ptr; } else { save=start; start=ptr; ptr->next=save; }

     printf("Want to add more node  Y|N   ");
     scanf(" %c", &ch);
   }    

   while(start!=NULL)
   {
    printf(" Data = %d\n", start->data);  
    start=start->next;
   }

}

lnishan commented 3 years ago

I'm not sure why we need a linked list here. Closing this.