Beruflich Dokumente
Kultur Dokumente
Announcements
Last date for course drop is 20th October. I will sign drop requests till 19th October. Friday Lab Sections: Lab 9 will be conducted on 18th (Tuesday) Monday Lab Sections: Lab 10 will not be today, but next week Tuesday Lab Sections: Lab 10 will not be tomorrow may be on 23rd. Lab exam in the week of 14th to 18th November Labs 11 and 12 will not be pre-announced to give you practice b d ill b d i i th November, 8:00 AM End-sem exam is on 25 Copies can be seen on 28th afternoon.
Lec-29
Recap
Linked lists
Deletion at the end Searching for a node Deletion in the middle Insertion in a sorted list
Lec-29
Lec-29
*left; *right;
Lec-29
Binary Tree
Lec-29
Lec-29
Family Tree
Lec-29
10
Lec-29
11
Family Tree
How would you
name the parents name the spouse name ALL siblings name ALL children
Lec-29
12
Stack
Last-in First-out Last in First out Example: A stack of books
you can only put books on top, or take out a book from the top trying to take out a book from the middle or put a book in the middle may cause all books to topple
Operations:
Push: Insert at the beginning Pop: Delete from the beginning
Lec-29
13
Stack
Some of you have implemented it using an array in a lab Can be easily implemented using regular (single pointer) linked list. Push
same as inserting a node at the beginning of the linked list
code given in lecture # 27
P Pop
same as deleting a node from the beginning of the linked list
code given in lecture #27
Lec-29
14
Queue
First-in First-out First in First out Example: queue at the railway reservation counter
you can only enter the queue at the end only the person at the head of the queue can leave the queue (hopefully, after getting the reservation)
Operations:
E Enqueue: Insert at the end I h d Dequeue: Delete from the beginning
Lec-29
15
Queue
Some of you have implemented it using an array in a lab Can be easily implemented using regular (single pointer) linked list. Enqueue
same as inserting a node at the end of the linked list
code given in lecture # 27
D Dequeue
same as deleting a node from the beginning of the linked list
code given in lecture #27
Lec-29
16
Queue
Note that either end of the linked list could have been called beginning/end
only thing that we need to do is to be consistent with this definition in dequeue and enqueue
Dequeue
same as deleting a node at the end of the linked list Code given in lecture #28
Lec-29 Dheeraj Sanghi, CSE Dept., IIT Kanpur ESc101, 2011-12-Monsoon 17
Queue
Note that in either implementation of queue
one operation is done in a single step the other operation requires traversal of the entire list
Lec-29
18
Lec-29
19
10
Lec-29
20
11
Removing a node
Let n be the pointer to the node that needs to be removed It will change head, if it is the first node. It will change tail, if it is the last node It will change both head and tail (to NULL), if it is the only node.
Lec-29
23
12
Removing a node
if (n->prev == NULL) (n prev head = n->next; else n->prev->next = n->next; if (n->next == NULL) tail = n->prev; else l n->next->prev = n->prev; free (n);
Lec-29
24
Any Questions?
Lec-29
25
13