1 / 16

Department of Technical Education Andhra Pradesh Name of : A Santhosh Kumar

Department of Technical Education Andhra Pradesh Name of : A Santhosh Kumar Designation : Lecturer Branch : Computer Engineering Institute : VMR Polytechnic, Rampur, Warangal Semester : III Subject : Data Structures through ‘C’.

Download Presentation

Department of Technical Education Andhra Pradesh Name of : A Santhosh Kumar

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. Department of Technical Education Andhra Pradesh Name of : A Santhosh Kumar Designation : Lecturer Branch : Computer Engineering Institute : VMR Polytechnic, Rampur, Warangal Semester : III Subject : Data Structures through ‘C’. Subject Code : 9CM305 Topic : Linear Data Structures Duration : 50 Mts Sub Topic : Creating a Single Linked List Teaching Aids to be used : Power Point Presentation, Animations Revised by : Bapuji naik 9CM305 .8

  2. Objectives After the Completion of this period, you would be able to know: • What is a Singly Linked List (SLL)? • How to create a Singly Linked List 9CM305 .8

  3. Recap In the last class, you have come to know • What is a linked list? • Advantages of linked lists over arrays • Purpose of a dummy header 9CM305 .8

  4. Singly Linked List • A Singly Linked List is a linked list in which each node has a link pointer to its successor. What is a Singly Linked List? 9CM305 .8

  5. SLL - More terminology • A node’s successor is the next node in the sequence • The last node has no successor • A node’s predecessor is the previous node in the sequence • The first node has no predecessor • A list’s length is the number of elements in it • A list may be empty (contain no elements) 9CM305 .8

  6. Common Operations on a Linked List • Traverse • Insert • Count • Delete • Search • Search and replace • Sort • Reverse 9CM305 .8

  7. temp header 18 786 24 X Operations - Traversing a SLL (animation) 9CM305 .8

  8. Common Operations (contd..) • Traverse – visiting nodes in a linked list • Insert – to add a node in the linked list • Count – number of nodes in the linked list • Delete – remove a node from the linked list 9CM305 .8

  9. Common Operations (contd..) • Search – locate a particular node in the liked list • Search and replace – Identify the node asked and replace with another given node • Sort – arrange all nodes of a liked list in an order • Reverse – to turn around the linked list 9CM305 .8

  10. Program – Declaration Part Singly Linked list - Creation # include <stdio.h.> typedef struct node { in info; struct node *link; } NODE; void append (NODE *) ; NODE *header =NULL; NODE *last=NULL; 9CM305 .8

  11. Singly Linked List - Creation Program – main program main () { NODE *temp; int data; char ch; do { temp = (NODE*)malloc(sizeof(NODE)); printf(“enter the values into new node”); scanf(“%d”,& data); temp  info = data; temp link = NULL; append( temp ); printf(“To append another node press Y”); scanf(“%c”, &ch); }while(ch ==‘Y’); } 9CM305 .8

  12. Here is a singly-linked list (SLL): The header points to the first node in the list (or contains the null link if the list is empty) Each node contains a value and a link to its successor (the last node has no successor) a b c d Singly-linked lists – creation (animation) Header X 9CM305 .8

  13. A singly linked list - Creation Discussion Point With the help of above animation, discuss the algorithm to create a singly linked list 9CM305 .8

  14. Singly Linked List - Creation Program – function part void append (t) { NODE *t; if (header == NULL) { header = t; last=header; } else { last->link= t; last=last ->link; } } 9CM305 .8

  15. Summary We have discussed - How a singly linked list looks? - Basic operations on a linked list - Program for creation of a singly Linked List 9CM305 .8

  16. Frequently asked questions • How to declare the structure of a node for a singly linked list? • Define a singly linked list • List various operations on a linked list • Explain about a singly linked list • Write a program to create a singly linked list 9CM305 .8

More Related