1 / 35

Linked Lists

Linked Lists. CH Gowri Kumar gkumar007@gmail.com. struct node { int data; struct node* next; }; typedef struct node Node; typedef struct node* List; List Initialize(); void InsertBegin(List l,int d); void InsertEnd(List l, int d); void Insert(List l, Node* pos,int d);

hinklea
Download Presentation

Linked Lists

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Linked Lists CH Gowri Kumar gkumar007@gmail.com

  2. struct node { int data; struct node* next; }; typedef struct node Node; typedef struct node* List; List Initialize(); void InsertBegin(List l,int d); void InsertEnd(List l, int d); void Insert(List l, Node* pos,int d); Node* Find(List l,int d); void Delete(List l, int d); http://www.gowrikumar.com

  3. Initialize InsertBegin InsertEnd Insert Find Delete Menu http://www.gowrikumar.com

  4. Initialize http://www.gowrikumar.com

  5. List Initialize() { Node* temp; temp = (Node*)calloc(1,sizeof(Node)); return temp; } http://www.gowrikumar.com

  6. head X List Initialize() { Node* temp; temp = (Node*)calloc(1,sizeof(Node)); return temp; } main() { List head; head = Initialize(); } http://www.gowrikumar.com

  7. InsertBegin http://www.gowrikumar.com

  8. 1 10 8 4 6 3 2 5 head X http://www.gowrikumar.com

  9. 1 10 8 4 6 3 2 5 head X void InsertBegin(List head,int d) { Node* temp; temp = (Node*)calloc(1,sizeof(Node)); temp->data = d; temp->next = head->next; head->next = temp; } http://www.gowrikumar.com

  10. 1 1 10 8 4 6 3 2 5 head X void InsertBegin(List head,int d) { Node* temp; temp = (Node*)calloc(1,sizeof(Node)); temp->data = d; temp->next = head->next; head->next = temp; } http://www.gowrikumar.com

  11. 1 1 10 8 4 6 3 2 5 head X http://www.gowrikumar.com

  12. 1 10 8 4 6 3 2 5 head X void InsertBegin(List head,int d) { Node* temp; temp = (Node*)calloc(1,sizeof(Node)); temp->data = d; temp->next = head->next; head->next = temp; } 1 http://www.gowrikumar.com

  13. 1 10 8 4 6 3 2 5 head X void InsertBegin(List head,int d) { Node* temp; temp = (Node*)calloc(1,sizeof(Node)); temp->data = d; temp->next = head->next; head->next = temp; } 1 http://www.gowrikumar.com

  14. 1 10 8 4 6 3 2 5 head X void InsertBegin(List head,int d) { Node* temp; temp = (Node*)calloc(1,sizeof(Node)); temp->data = d; head->next = temp; temp->next = head->next; } 1 http://www.gowrikumar.com

  15. 1 1 10 8 4 6 3 2 5 head X void InsertBegin(List head,int d) { Node* temp; temp = (Node*)calloc(1,sizeof(Node)); temp->data = d; temp->next = head->next; head->next = temp; } http://www.gowrikumar.com

  16. 1 10 1 10 8 4 6 3 2 5 head X void InsertBegin(List head,int d) { Node* temp; temp = (Node*)calloc(1,sizeof(Node)); temp->data = d; temp->next = head->next; head->next = temp; } http://www.gowrikumar.com

  17. 1 10 1 10 8 4 6 3 2 5 head X void InsertBegin(List head,int d) { Node* temp; temp = (Node*)calloc(1,sizeof(Node)); temp->data = d; head->next = temp; temp->next = head->next; } http://www.gowrikumar.com

  18. InsertEnd http://www.gowrikumar.com

  19. tail 10 1 1 10 8 4 6 3 2 5 head X void InsertEnd(List head,int d) { Node *tail,*temp; tail = head; . . . . . . . . . . . . . . . . } http://www.gowrikumar.com

  20. tail 10 1 1 10 8 4 6 3 2 5 head X void InsertEnd(List head,int d) { Node *tail,*temp; tail = head; while(tail->next != NULL) tail = tail->next; . . . . . . . . . . . . . . . . } http://www.gowrikumar.com

  21. tail 10 1 1 10 8 4 6 3 2 5 head X void InsertEnd(List head,int d) { Node *tail,*temp; tail = head; while(tail->next != NULL) tail = tail->next; . . . . . . . . . . . . . . . . } http://www.gowrikumar.com

  22. tail 8 10 1 1 10 8 4 6 3 2 5 head X void InsertEnd(List head,int d) { . . . . . . . . . . . . . . . . temp = (Node*)calloc(1,sizeof(Node)); temp->data = d; tail->next = temp; } http://www.gowrikumar.com

  23. Insert http://www.gowrikumar.com

  24. 10 1 8 1 10 8 4 6 3 2 5 head X void Insert(List head,Node* p,int d) { temp = (Node*)calloc(1,sizeof(Node)); temp->data = d; temp->next = p->next; p->next = temp; } http://www.gowrikumar.com

  25. 4 10 1 8 1 10 8 4 6 3 2 5 head X void Insert(List head,Node* p,int d) { temp = (Node*)calloc(1,sizeof(Node)); temp->data = d; temp->next = p->next; p->next = temp; } http://www.gowrikumar.com

  26. 10 1 4 1 10 8 4 6 3 2 5 head X 8 http://www.gowrikumar.com

  27. Find http://www.gowrikumar.com

  28. 10 1 4 1 10 8 4 6 3 2 5 head X 8 void Find(List l,Node* p,int d) { Node *temp; temp = l; while(temp->next != NULL) { if(temp->next->data == d) return temp; temp = temp->next; } return NULL; } http://www.gowrikumar.com

  29. temp 4 1 10 1 10 8 4 6 3 2 5 head X 8 void Find(List l,Node* p,int d) { Node *temp; temp = l; while(temp->next != NULL) { if(temp->next->data == d) return temp; temp = temp->next; } return NULL; } http://www.gowrikumar.com

  30. Delete http://www.gowrikumar.com

  31. 10 4 1 1 10 8 4 6 3 2 5 head X 8 void Delete(List l,Node* p,int d) { Node *temp,*del; temp = Find(l,d); if(temp != NULL) { del = temp->next; temp->next = del->next; free(del); } } http://www.gowrikumar.com

  32. del temp 1 4 10 1 10 8 4 6 3 2 5 head X 8 void Delete(List l,Node* p,int d) { Node *temp,*del; temp = Find(l,d); if(temp != NULL) { del = temp->next; temp->next = del->next; free(del); } } http://www.gowrikumar.com

  33. 10 4 8 10 8 4 6 3 2 5 head X http://www.gowrikumar.com

  34. int main { List l; Node* temp; l = Initialize(); InsertBegin(l,1); InsertBegin(l,10); InsertEnd(l,8); temp = Find(l,8); Insert(l,temp,4); Delete(l,1); } http://www.gowrikumar.com

  35. The End http://www.gowrikumar.com

More Related