CHAPTER 12 LINKED LIST SRM-MCA.

Slides:



Advertisements
Similar presentations
Stacks, Queues, and Linked Lists
Advertisements

DATA STRUCTURES USING C++ Chapter 5
Singly Linked List BTECH, EE KAZIRANGA UNIVERSITY.
Computer Programming for Engineering Applications ECE 175 Intro to Programming.
Data Structure Lecture-5
Data Structures: A Pseudocode Approach with C
COMP103 - Linked Lists (Part A)1 Chapter 17 Truly dynamic memory management.
Class 3: Linked Lists. cis 335 Fall 2001 Barry Cohen What is a linked list? n A linked list is an ordered series of ‘nodes’ n Each node contains some.
Linked Lists Chained nodes of information create what are called linked lists, with each node providing a link to the next node. A useful feature of linked.
Reference: Vinu V Das, Principles of Data Structures using C and C++
Implementation of Linked List For more notes and topics visit: eITnotes.com.
UNIT 1 Data Structures Using C Linked List By Rohit Khokher Department of Computer Science, Vidya College of Engineering, Meerut, India.
17. ADVANCED USES OF POINTERS. Dynamic Storage Allocation Many programs require dynamic storage allocation: the ability to allocate storage as needed.
1 Chapter 16-1 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion.
Advanced Data types and Sorting
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.
Lists II. List ADT When using an array-based implementation of the List ADT we encounter two problems; 1. Overflow 2. Wasted Space These limitations are.
1 CS 132 Spring 2008 Chapter 3 Pointers and Array-Based Lists read p
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 17: Linked Lists.
1 Chapter 16 Linked Structures Dale/Weems/Headington.
Linked List Chapter Data Abstraction separates the logical properties of a data type from its implementation LOGICAL PROPERTIES – What are the.
ENEE150 – 0102 ANDREW GOFFIN Project 4 & Function Pointers.
Algorithms and Data Structures
Computer Programming for Engineering Applications ECE 175 Intro to Programming.
Data Structures AZHAR MAQSOOD NUST Institute of Information Technology (NIIT) Lecture 6: Linked Lists Linked List Basics.
LINEAR LINKED LISTS The disadvantages of arrays: 1.The size of the array is fixed. 2.Large size of array??? 3. Inserting and deleting elements. If the.
MORE POINTERS Plus: Memory Allocation Heap versus Stack.
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.
1 Linked List. 2 List A list refers to a sequence of data items  Example: An array The array index is used for accessing and manipulation of array elements.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Linked Lists Outline Introduction Self-Referential Structures.
STRUCTURES. INTRODUCTION A structure is same as that of records. It stores related information about an entity. Structure is basically a user defined.
1 CS 132 Spring 2008 Chapter 5 Linked Lists p
Linked Lists Chapter Introduction To The Linked List ADT Linked list: set of data structures (nodes) that contain references to other data structures.
Chapter 6. Character String Types It is one in which the values consists of sequences of characters. How to Define a variable contain a string? In a programming.
Data Structures: A Pseudocode Approach with C 1 Chapter 5 Objectives Upon completion you will be able to: Explain the design, use, and operation of a linear.
Pointers and Linked Lists
Linked List Insert as a first node Insert as a last node
Linked List :: Basic Concepts
Pointers and Linked Lists
Lectures linked lists Chapter 6 of textbook
UNIT – I Linked Lists.
Linked Lists Chapter 6 Section 6.4 – 6.6
Linking in double direction
Data Structure and Algorithms
Linked List.
UNIT-3 LINKED LIST.
Programming Structures.
Visit for more Learning Resources
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.
Linked lists Motivation: we can make arrays, but their functionality is slightly limited and can be difficult to work with Biggest issue: size management.
Sequences 9/18/ :20 PM C201: Linked List.
Programmazione I a.a. 2017/2018.
Buy book Online -
Chapter 16-2 Linked Structures
LINKED LISTS.
S. Kiran, PGT (CS) KV, Malleswaram
Chapter 18: Linked Lists.
Linked List Insert as a first node Insert as a last node
Pointers and Linked Lists
Stack and Queues Stack implementation using Array
FILE HANDLING IN C.
Data structure types. Linear and Non-Linear Data Structures: Linked lists, stacks and queues.
Linked List.
Chapter 17: Linked Lists.
Chapter 16 Linked Structures
LINKED LIST.
Linked Lists Adapted from Dr. Mary Eberlein, UT Austin.
Data Structures & Algorithms
Structures, Unions, and Enumerations
Presentation transcript:

CHAPTER 12 LINKED LIST SRM-MCA

Session Objectives Explain Data Structures Explain link list Explain linked list declaration Traverse a linked list Insert nodes into a link list Types of linked list

Data structures syntax A data structure is a group of data elements grouped together under one name. These data elements, known as members, can have different types and different lengths. syntax struct structure_name { member_type1 member_name1; member_type2 member_name2; member_type3 member_name3; } Stru_varname; Where structure_name is a name for the structure type, stru_name can be a set of valid identifiers for objects that have the type of this structure. Within braces { } there is a list with the data members, each one is specified with a type and a valid identifier as its name.

// program to Accept the employee details from the End user #include<stdio.h> #include<conio.h> #include<malloc.h> struct emp { int eno; char ename[25]; int sal; }; void main() struct emp *e; char ch='y'; clrscr(); while(ch=='y')

{ e=(struct emp *) malloc(sizeof(struct emp)); printf("\n Enter the employee number"); scanf("%d",&e->eno); printf("\n Enter the employee name"); scanf("%s",e->ename); printf("\n Enter the employee salary"); scanf("%d",&e->sal); printf("\n Do you wish to continue[Y/N]?"); fflush(stdin); scanf("%c",&ch); } getch();

LINKED LIST : It is a dynamic data structure. This implementation uses pointers. Each element of the list is called as node. Each element points to the next element. In linked list, a node can be inserted or deleted at any position. Basic Terms : (i) Node (ii) Null Pointer (iii) External pointer (iv) Empty List Operation on Linked list : (i) Creation (ii) Traversing (iii) Insertion (a) Insertion at beginning (b) Insertion at end (c) Insertion at any position (iv) Searching (v) Deletion (a) Deletion at beginning (b) Deletion at end (c) Deletion at any position

Linked List Declaration A linked list storing information of players of a cricket team can be declared as : Note That next is declared as a pointer to the structure player itself. struct player { char name[30]; struct player *next; }; Remember, that the last node in the list should have its pointer, next, set to the value NULL.

Diagrammatically

// program to Add New Records in Single linked list using First to // Last method simply defined as to form the new Datastructure #include<stdio.h> #include<conio.h> #include<malloc.h> void accept(); struct emp { int eno; char ename[25]; int sal; struct emp *next; }; // start - Ist Record, New1 - Current record, Temp - prevoius record struct emp *start=NULL,*new1=NULL,*temp=NULL,*new2,*dptr; void main() char ch='y'; int no,recno; clrscr(); while(ch=='y') new1=(struct emp *) malloc(sizeof(struct emp)); printf("\n Enter the employee number"); scanf("%d",&new1->eno); Continued…,

printf("\n Enter the employee name"); scanf("%s",new1->ename); printf("\n Enter the employee salary"); scanf("%d",&new1->sal); if (start==NULL) // Give Ist record as Input,to enter the following if true { start=new1; //current record is assigned to start start->next=NULL; //current record next is set to NULL.because it is a // first record temp=new1; //current record is assigned to temp(point previous record) } else temp->next=new1; // new1 have a current record &assigned to prevoius next // have a NULL value changed to address temp=new1; //current i/p record is assigned to temp ex. 1st record to II temp->next=NULL; printf("\n Do you wish to continue[Y/N]?"); fflush(stdin); scanf("%c",&ch); Continued…,

printf("\n %d %s %d",new1->eno,new1->ename,new1->sal); } // View ALL Records for(new1=start;new1!=NULL; new1=new1->next) // new1 initialize Ist record { printf("\n %d %s %d",new1->eno,new1->ename,new1->sal); } //Viewing particular records printf("\n Enter the employee number to be displayed"); scanf("%d",&no); if (no==new1->eno) // Insert the record at the middle position printf("\n ENter the Record No is to be inserted"); scanf("%d",&recno); accept(); for(new2=start;new2!=NULL;new2=new2->next) if(recno==start->eno) // to search if it is Ist record new1->next=start; start=new1; Continued…,

else if (recno==new2->eno && new2->next !=NULL) { temp->next=new1; new1->next=new2; } // to check if it is last record &also to insert that place. else if (recno==new2->eno && new2->next==NULL) { new2->next=new1; new1->next=NULL; temp=new2; // display all records for(new2=start;new2!=NULL; new2=new2->next) // new2 initialize Ist record printf("\n %d %s %d",new2->eno,new2->ename,new2->sal); Continued…,

printf("\n Enter the record number to delete"); scanf("%d",&recno); //Deletion process printf("\n Enter the record number to delete"); scanf("%d",&recno); for(new2=start;new2!=NULL;new2=new2->next) { if(recno==start->eno) start=start->next; } else if (recno==new2->eno && new2->next !=NULL) temp->next=new2->next; else if(recno==new2->eno && new2->next==NULL) {temp->next=NULL;} temp=new2; //display all the records for(new2=start;new2!=NULL; new2=new2->next) // new2 initialize Ist record printf("\n %d %s %d",new2->eno,new2->ename,new2->sal); Continued…,

printf("\n Enter the employee number to be modified"); // Modify process printf("\n Enter the employee number to be modified"); scanf("%d",&no); for(new1=start;new1!=NULL; new1=new1->next) //new1 init.Ist record & search { if (no==new1->eno) printf("\n Enter the Empno,Empname and salary"); scanf("\n %d %s %d",&new1->eno,new1->ename,&new1->sal); } //display all the records for(new1=start;new1!=NULL; new1=new1->next) // new1 initialize Ist record printf("\n %d %s %d",new1->eno,new1->ename,new1->sal); //Memory deallocating process new1=start; Continued…,

while(1){ if(new1==NULL) break; dptr=new1; new1=new1->next; free(dptr); } dptr=NULL; new1=NULL; temp=NULL; start=NULL; void accept() { new1=(struct emp *) malloc(sizeof(struct emp)); printf("\n Enter the employee number"); scanf("%d",&new1->eno); printf("\n Enter the employee name"); scanf("%s",new1->ename); printf("\n Enter the employee salary"); scanf("%d",&new1->sal);}}