UNIT 1 Data Structures Using C Linked List By Rohit Khokher Department of Computer Science, Vidya College of Engineering, Meerut, India.

Slides:



Advertisements
Similar presentations
EENG212 Algorithms and Data Structures
Advertisements

Linked Lists Linked Lists Representation Traversing a Linked List
LINKED LIST, STACKS AND QUEUES Saras M Srivastava, PGT – Comp. Sc. Kendriya Vidyalaya TengaValley.
Singly Linked List BTECH, EE KAZIRANGA UNIVERSITY.
Computer Programming for Engineering Applications ECE 175 Intro to Programming.
Data Structure Lecture-5
Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
Sort the given string, without using string handling functions.
Operations on Arrays. Operation on Array Data Structures  Traversal  Selection  Searching  Insertion  Deletion  Sorting.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
UNIT-2. Singly Linked List Doubly Linked List Circular Linked List Representing Stack with Linked List. Representing Queue with Linked List.
Reference: Vinu V Das, Principles of Data Structures using C and C++
Implementation of Linked List For more notes and topics visit: eITnotes.com.
PRESENTATION ON SEARCHING SEARCHING Searching is the method to find element from the list of the elements. If element is found then it.
Data Strcutures.
D ATA S TRUCTURE Ali Abdul Karem Habib MSc.IT. P OINTER A pointer is a variable which represents the location of a data item. We can have a pointer to.
Linked Lists. A linear linked list is a collection of objects, called nodes, each of which contains a data item and a pointer to the next node in the.
Department of Computer Science Data Structures Using C++ 2E Chapter 5 Linked Lists.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 17: Linked Lists.
1 Chapter 16 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion and.
1 Chapter 16 Linked Structures Dale/Weems/Headington.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Data Structures Dale Roberts, Lecturer Computer Science,
1. Circular Linked List In a circular linked list, the last node contains a pointer to the first node of the list. In a circular linked list,
Algorithms and Data Structures
Computer Programming for Engineering Applications ECE 175 Intro to Programming.
Review Sorting algorithms Selection Sort Insertion Sort Bubble Sort Merge Sort Quick Sort.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
Definition: A stack is an ordered collection of elements in which insertions(Push) and deletions(Pop) are restricted to one end. LIFO(Last In First Out)
Concepts of Algorithms CSC-244 Unit 19 & 20 Binary Search Tree (BST) Shahid Iqbal Lone Computer College Qassim University K.S.A.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Elementary Data Structures Linked Lists Linked Lists Dale.
CIRCULAR L INKED L IST Insert as a first node Insert as a last node Delete first node Delete last node Insert after a node Insert before a node Search.
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
Linked list: a list of items (nodes), in which the order of the nodes is determined by the address, called the link, stored in each node C++ Programming:
Linked List. LINKED LIST Link is collection of similar type of elements. There are two ways of maintaining a list in memory. The first way is store the.
Data Structure & Algorithms
Computer Science Department Data Structure and Algorithms Lecture 3 Stacks.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Linked Lists Outline Introduction Self-Referential Structures.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 17: Linked Lists.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 18: Linked Lists.
CHAPTER 51 LINKED LISTS. Introduction link list is a linear array collection of data elements called nodes, where the linear order is given by means of.
1. Traversing a linear array Here A is a linear array with lower bound LB and upper bound UB. This algorithm traverses A applying an operation PROCESS.
Sorting and Searching Bubble Sort Linear Search Binary Search.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Doubly / Two Way Linked List It is linear collection of data elements, called nodes, where each node N is divided into three parts: – An information field.
LIST Unsorted 1.Set PTR := START 2.Repeat Step 3 while PTR=NULL 3.If ITEM = INFO[PTR], then : Set LOC := PTR and Exit else Set PTR:=LINK[PTR] [PTR points.
C++ Programming:. Program Design Including
Linked List :: Basic Concepts
5.13 Recursion Recursive functions Functions that call themselves
Lectures linked lists Chapter 6 of textbook
Review Deleting an Element from a Linked List Deletion involves:
Elementary Data Structures
Prepared by, Jesmin Akhter, Lecturer, IIT, JU
Lecture - 6 On Data Structures
UNIT-3 LINKED LIST.
Linked list.
Linked-list.
Linked lists.
Linked Lists A linked list or one way list is a linear collection of data elements called nodes where the order is given by means of pointers It is divided.
Linked Lists head One downside of arrays is that they have a fixed size. To solve this problem of fixed size, we’ll relax the constraint that the.
Sequences 9/18/ :20 PM C201: Linked List.
Programmazione I a.a. 2017/2018.
INSERTION INTO A LINEAR ARRAY Set J = N Repeat step 3 and 4 while J>= K Set LA[ J+1] = LA [ J ] Set J = J-1 Set LA [K] = ITEM Set N = N+1 Exit.
Stack and Queues Stack implementation using Array
Stack and Queues Stack implementation using Array
LINKED LIST.
Abstract Data Type Abstract Data Type as a design tool
Chapter 16 Linked Structures
General List.
Linked lists.
Presentation transcript:

UNIT 1 Data Structures Using C Linked List By Rohit Khokher Department of Computer Science, Vidya College of Engineering, Meerut, India

UNIT 1 LINKED LIST  A Linked List is a linear collection of data elements called nodes, where the linear order is given by means of pointers.  The each node is divided into two parts: the first part contain the information of the element, and the second part, called the link field contains the address of t he next node in the list. x START LINK LIST WITH 4 NODES

UNIT 1  The pointer of the last node contains a special value called a null pointer which is any invalid address.  The value of null character is either ’0’ or ‘any negative value’.  The linked list also contains a list pointer variable called start which contains the address of the first node of the link list.  A special case in a list is that has no node such that list is called a null or empty list and it is represented by the null pointer in the start.  Example:- create a link list for marks of five subject 89,75,78,80,74 in ascending order

UNIT START LINK LIST REPRESENTATION OF THE MARKS

UNIT 1 ALGORITHM FOR TRAVERSING A LINKED LIST 1.Set PTR=START [Initializes pointer PTR] 2.Repeat steps 3 & 4 while PTR != NULL 3.Apply process to INFO[PTR] 4. Set PTR:- LINK[PTR] [PTR now points to next node] [End of step 2 loop] 5. Exit

UNIT 1 PTR PTR=LINK[PTR]

UNIT 1 ALGORITHM FOR SEARCHING IN A UNSORTED LINKED LIST SEARCH(INFO,LINK,START,ITEM,LOC) 1.SET PTR = START 2.REPEAT STEP 3 WHILE PTR != NULL 3.IF ITEM = INFO[PTR] then SET LOC = PTR & EXIT ELSE SET PTR= LINK[PTR] [PTR now points to the next node][END OF IF STRUCTURE] [END OF STEP 2 LOOP] 4.[SEARCH IS UNSUCESSFUL] SET LOC=NULL 5.EXIT

UNIT 1 ALGORITHM FOR SEARCHING IN SORTED LIST SRCHSL(INFO,LINK,START,ITEM,LOC) 1.SET PTR = START 2.REPEAT STEP 3 WHILE PTR != NULL 3.IF ITEM < INFO[PTR] then; SET PTR = LINK[PTR] [PTR now points to the next node] ELSE IF ITEM = INFO [PTR] then; SET LOC = PTR & EXIT [search is successful] ELSE SET LOC = NULL & EXIT [item now exceed INFO[PTR]] [END OF IF STRUCTURE] [END OF STEP 2 LOOP] 4.[SEARCH IS UNSUCESSFUL] SET LOC=NULL 5.EXIT

UNIT 1 OVERFLOW & UNDERFLOW CONDITIONS OVERFLOW will occur with our link list when AVAIL= NULL &there is an insertion UNDERFLOW will occur with our link list when START=NULL & there is a deletion.

UNIT 1 INSERTION IN A LINKED LIST This Can Be Done In Three Ways: 1.Beginning of the list 2.Between two nodes 3.In a sorted list

UNIT 1 AT BEGINNING OF THE LINKED LIST x START x AVAIL

UNIT 1 x START x AVAIL

UNIT 1 ALGORITHM FOR INSERTION AT BEGINNING INSFIRST(INFO,LINK,START,AVAIL,ITEM) 1.[OVERFLOW] if AVAIL=NULL, then write OVERFLOW & EXIT 2.[ Remove first node from AVAIL list] set NEW = AVAIL & AVAIL= LINK[AVAIL] 3.Set INFO[NEW]=ITEM [copies new data into new node] 4.Set LINK[NEW]= START [new node points to original first node] 5.Set START= NEW [changes START so it points to the new node] 6.exit

UNIT 1 INSERT AFTER A GIVEN NODE x START x AVAIL Node ANode B

UNIT 1 x START x AVAIL Node A Node B Node N

UNIT 1 ALGORITHM FOR INSERTION AT POSITION INSLOC(INFO,LINK,START,AVAIL,LOC,ITEM) 1.[OVERFLOW] if AVAIL=NULL, then write OVERFLOW & EXIT 2.[ Remove first node from AVAIL list] set NEW = AVAIL & AVAIL= LINK[AVAIL] 3.Set INFO[NEW]=ITEM [copies new data into new node] 4.If LOC=NULL then [INSERT AS A FIRST NODE] set LINK[NEW]= START & START=NEW else [INSERT node after node with location LOC] set LINK[NEW]=LINK[LOC] & LINK[LOC]=NEW; [END OF IF STRUCTURE] 5.exit

UNIT 1 CREATION OF LINKED LIST #include void main() { struct node { int num; struct node *ptr; }; typedef struct node NODE; NODE *head, *first, *temp; int count=0; int choice=1; first=NULL; while(choice) { head=(NODE *)malloc(sizeof(NODE)); printf("Enter the data item\n"); scanf("%d",&head->num); if(first!=NULL) { temp->ptr=head; temp=head; }

UNIT 1 else { first=temp=head; } fflush(stdin); printf("Do you want to continue(type 0 or 1)?\n"); scanf("%d",&choice); } temp->ptr=NULL; temp=first; printf("Status of the linked list is\n"); while(temp!=NULL) { printf("%d",temp->num); count++; temp=temp->ptr; } printf("NULL"); printf("NO of nodes in the list =%d\n",count); getch(); }

UNIT 1 Output of the Program Enter the data item 1 Do you want to continue(type 0 or 1)? 1 Enter the data item 2 Do you want to continue(type 0 or 1)? 1 Enter the data item 3 Do you want to continue(type 0 or 1)? 1 Enter the data item 4 Do you want to continue(type 0 or 1)? 0 Status of the linked list is 1234NULLNO of nodes in the list =4

UNIT 1 Insertion in Linked List #include struct node { int info; struct node *next; }; typedef struct node NODE; NODE *start; void createmptylist(NODE *start) { *start=(NODE *)NULL; } void traversinorder(NODE *start) { while(start != (NODE *) NULL) { printf("%d\n",start->info); start=start->next; }

UNIT 1 void insertatbegin(int item) { NODE *ptr; ptr=(NODE *)malloc(sizeof(NODE)); ptr->info=item; if(start==(NODE *)NULL) ptr->next=(NODE *)NULL; else ptr->next=start; start=ptr; } void insert_at_end(int item) { NODE *ptr,*loc; ptr=(NODE *)malloc(sizeof(NODE)); ptr->info=item; ptr->next=(NODE *)NULL; if(start==(NODE*)NULL) start=ptr;

UNIT 1 else { loc=start; while(loc->next!=(NODE *)NULL) loc=loc->next; loc->next=ptr; } void insert_spe(NODE *start,int item) { NODE *ptr,*loc; int temp,k; for(k=0,loc=start;k<temp;k++) { loc=loc->next; if(loc==NULL) { printf("node in the list at less than one\n"); return; }

UNIT 1 ptr=(NODE *)malloc(sizeof(NODE)); ptr->info=item; ptr->next=loc->next;; loc->next=ptr; } void main() { int choice,item,after; char ch; clrscr(); createmptylist(start); do { printf("1.Insert element at begin \n"); printf("2. insert element at end positon\n"); printf("3. insert specific the position\n"); printf("4.travers the list in order\n"); printf("5. exit\n");

UNIT 1 printf("enter your choice\n"); scanf("%d",&choice); switch(choice) { case 1: printf("Enter the item\n"); scanf("%d",&item); insertatbegin(item); break; case 2: printf("Enter the item\n"); scanf("%d",&item); insert_at_end(item); break; case 3: printf("Enter the item\n"); scanf("%d",&item); insert_spe(start,item); break;

UNIT 1 case 4: printf("\ntravers the list\n"); traversinorder(start); break; case 5: return; } fflush(stdin); printf("do your want continous(y for yes)\n"); scanf("%c",&ch); }while((ch='y')||(ch='Y')); getch(); }

UNIT 1 THANKS