Linked lists
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Linked lists

  • 4,976 views
Uploaded on

This presentations gives an introduction to the data structure linked-lists. I discuss the implementation of header-based linked-lists in C. The presentation runs through the code and provides the......

This presentations gives an introduction to the data structure linked-lists. I discuss the implementation of header-based linked-lists in C. The presentation runs through the code and provides the visualization of the code w.r.t pointers.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
4,976
On Slideshare
4,954
From Embeds
22
Number of Embeds
5

Actions

Shares
Downloads
324
Comments
1
Likes
4

Embeds 22

http://www.slideshare.net 11
http://www.linkedin.com 4
https://www.linkedin.com 4
http://www.fachak.com 2
http://imamu.blackboard.com 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Linked Lists CH Gowri Kumar [email_address]
  • 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);
  • 3. Menu
    • Initialize
    • InsertBegin
    • InsertEnd
    • Insert
    • Find
    • Delete
  • 4. Initialize
  • 5. List Initialize() { Node* temp; temp = (Node*)calloc(1,sizeof(Node)); return temp; }
  • 6. List Initialize() { Node* temp; temp = (Node*)calloc(1,sizeof(Node)); return temp; } main() { List head; head = Initialize(); } X head
  • 7. InsertBegin
  • 8. X head 1 10 8 4 6 3 2 5
  • 9. X head 1 10 8 4 6 3 2 5 void InsertBegin(List head,int d) { Node* temp; temp = (Node*)calloc(1,sizeof(Node)); temp->data = d; temp->next = head->next; head->next = temp; }
  • 10. X head 1 10 8 4 6 3 2 5 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
  • 11. X head 1 10 8 4 6 3 2 5 1
  • 12. 1 10 8 4 6 3 2 5 void InsertBegin(List head,int d) { Node* temp; temp = (Node*)calloc(1,sizeof(Node)); temp->data = d; temp->next = head->next; head->next = temp; } X head 1
  • 13. 1 10 8 4 6 3 2 5 void InsertBegin(List head,int d) { Node* temp; temp = (Node*)calloc(1,sizeof(Node)); temp->data = d; temp->next = head->next; head->next = temp; } X head 1
  • 14. 1 10 8 4 6 3 2 5 void InsertBegin(List head,int d) { Node* temp; temp = (Node*)calloc(1,sizeof(Node)); temp->data = d; head->next = temp; temp->next = head->next; } X head 1
  • 15. X head 1 10 8 4 6 3 2 5 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
  • 16. X head 1 10 8 4 6 3 2 5 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 10
  • 17. X head 1 10 8 4 6 3 2 5 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 10
  • 18. InsertEnd
  • 19. X head 1 10 8 4 6 3 2 5 void InsertEnd(List head,int d) { Node *tail,*temp; tail = head; . . . . . . . . . . . . . . . . } 10 1 tail
  • 20. 1 10 8 4 6 3 2 5 void InsertEnd(List head,int d) { Node *tail,*temp; tail = head; while(tail->next != NULL) tail = tail->next; . . . . . . . . . . . . . . . . } X head 10 1 tail
  • 21. 1 10 8 4 6 3 2 5 void InsertEnd(List head,int d) { Node *tail,*temp; tail = head; while(tail->next != NULL) tail = tail->next; . . . . . . . . . . . . . . . . } X head 10 1 tail
  • 22. X head 1 10 8 4 6 3 2 5 void InsertEnd(List head,int d) { . . . . . . . . . . . . . . . . temp = (Node*)calloc(1,sizeof(Node)); temp->data = d; tail->next = temp; } 10 1 8 tail
  • 23. Insert
  • 24. X head 1 10 8 4 6 3 2 5 void Insert(List head,Node* p,int d) { temp = (Node*)calloc(1,sizeof(Node)); temp->data = d; temp->next = p->next; p->next = temp; } 10 1 8
  • 25. X head 1 10 8 4 6 3 2 5 void Insert(List head,Node* p,int d) { temp = (Node*)calloc(1,sizeof(Node)); temp->data = d; temp->next = p->next; p->next = temp; } 10 1 8 4
  • 26. X head 1 10 8 4 6 3 2 5 8 10 1 4
  • 27. Find
  • 28. X head 1 10 8 4 6 3 2 5 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; } 10 1 4
  • 29. X head 1 10 8 4 6 3 2 5 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; } 10 1 4 temp
  • 30. Delete
  • 31. X head 1 10 8 4 6 3 2 5 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); } } 10 4 1
  • 32. X head 1 10 8 4 6 3 2 5 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); } } 10 4 1 temp del
  • 33. X head 10 8 4 6 3 2 5 10 4 8
  • 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); }
  • 35. The End