ICS121 – Data Structures I

1 of
Published on Video
Go to video
Download PDF version
Download PDF version
Embed video
Share video
Ask about this video

Page 1 (0s)

ICS121 – Data Structures I. Module 1 Circular Linked List, Doubly Linked List, Doubly Circular Linked List and Applications.

Page 2 (9s)

Circular Linked List: Representation of Node: struct node.

Page 3 (20s)

Insertion Operation: Insertion at Beginning: struct node *ptr,*temp; int item; ptr = (struct node *)malloc(sizeof(struct node)); if(ptr == NULL) Write “OVERFLOW"; else { Read item; ptr -> data = item; if(head == NULL) {.

Page 4 (39s)

Insertion Operation: Insertion at Last:. struct node *ptr,*temp; int item; ptr = (struct node *)malloc(sizeof(struct node)); if(ptr == NULL) Write "OVERFLOW"; else { Read item; ptr->data = item;.

Page 5 (59s)

Deletion: Deletion at Beginning: struct node *ptr; if(head == NULL) Write "UNDERFLOW"; else if(head->next == head) else {.

Page 6 (1m 14s)

} else { ptr = head;. Deletion: Deletion at Last: struct node *ptr, *ptr1; while(ptr ->next != head) else if (head ->next == head) ptr1->next = ptr -> next; free(head);.

Page 7 (1m 27s)

Se. arching:. flag=0; } } if(flag != 0) else Write "Item not found";.

Page 8 (1m 46s)

Tracing:. struct node *ptr; ptr=head; if(head == NULL) write "nothing to print"; else Write ptr -> data; }.

Page 9 (1m 58s)

Doubly Linked List: Representation of Node: struct node.

Page 10 (2m 8s)

Insertion Operation: Insertion at Beginning: struct node *ptr; int item; ptr = (struct node *)malloc(sizeof(struct node)); if(ptr == NULL) write “OVERFLOW"; else { read item; if(head==NULL) { ptr->next = NULL;.

Page 11 (2m 24s)

Insertion Operation: Insertion at Last: struct node *ptr,*temp; int item; ptr = (struct node *) malloc(sizeof(struct node)); if(ptr == NULL) write "OVERFLOW"; else { Read item; ptr->data=item; if(head == NULL).

Page 12 (2m 42s)

Insertion Operation: Insertion at random position: struct node *ptr,*temp; Declare item, loc, i; ptr = (struct node *)malloc(sizeof(struct node)); if(ptr == NULL) Write “OVERFLOW"; else { temp=head; Read loc; for(i=0;i<loc;i++).

Page 13 (3m 1s)

Deletion: Deletion at Beginning: struct node *ptr; if(head == NULL) Write “UNDERFLOW"; else if(head->next == NULL) else {.

Page 14 (3m 14s)

head = NULL; free(head); } else { ptr = head;. Deletion: Deletion at Last: struct node *ptr; if(ptr->next != NULL) write “UNDERFLOW"; ptr ->prev -> next = NULL; else if(head->next == NULL) free(ptr);.

Page 15 (3m 27s)

Deletion: Deletion at random: struct node *ptr, *temp; Declare val; Read an item to delete ptr = head; while(ptr -> data != val) ptr = ptr -> next; if(ptr -> next == NULL) Write “No item"; else if(ptr -> next -> next == NULL) { ptr ->next = NULL;.

Page 16 (3m 47s)

Searching: struct node *ptr; declare item,i=0,flag; ptr = head; if(ptr == NULL) Write “empty list” else { Read search item; while (ptr!=NULL) { if(ptr->data == item) {.

Page 17 (4m 3s)

Doubly Circular Linked List: Representation of Node: struct node.

Page 18 (4m 12s)

Insertion Operation: Insertion at Beginning: struct node *ptr,*temp; int item; ptr = (struct node *)malloc(sizeof(struct node)); if(ptr == NULL) Write "OVERFLOW"; else { Read item; ptr->data=item; if(head==NULL) { head = ptr; ptr -> next = head;.

Page 19 (4m 33s)

Insertion Operation: Insertion at Last:. struct node *ptr,*temp; int item; ptr = (struct node *) malloc(sizeof(struct node)); if(ptr == NULL) Write "OVERFLOW"; else { Read item; ptr->data=item; if(head == NULL).

Page 20 (4m 53s)

Deletion: Deletion at Beginning: struct node *temp; if(head == NULL) Write " UNDERFLOW"; else if(head->next == head) else {.

Page 21 (5m 9s)

Deletion: Deletion at Last: struct node *ptr; if(head == NULL) write " UNDERFLOW"; else if(head->next == head) else {.

Page 22 (5m 24s)

Searching:. struct node *ptr; Int item, i=0,flag=1; ptr = head; if(ptr == NULL) write “Empty List"; else else { while (ptr->next != head).

Page 23 (5m 43s)

Tracing:. struct node *ptr; ptr=head; if(head == NULL) Write “empty list"; else write ptr -> data; }.

Page 24 (5m 55s)

Advantage:. Easier to insert or delete data elements Dynamic data structure Memory efficient Implementation Disadvantage: Slow search operation and requires more memory space Backtracking or reverse traversing is difficult. In a doubly linked list, it is easier but requires more memory to store the back pointer. Applications: Implementing stacks, queues, binary trees, and graphs of predefined size. Implement dynamic memory management functions of the operating system. Polynomial implementation for mathematical operations Circular linked list is used to implement OS or application functions that require round-robin execution of tasks. Circular linked list is used in a slide show where a user wants to return to the first slide after the last slide is displayed. Doubly linked list is used in the implementation of forward and backward buttons in a browser to move backward and forward in the opened pages of a website. Circular queue is used to maintain the playing sequence of multiple players in a game..