Linked List Insert as a first node Insert as a last node

Slides:



Advertisements
Similar presentations
Page 11 Solutions to Practice Problems Using a Linked List From Previous Days Notes Create C functions to solve the following problems with linked lists.
Advertisements

EENG212 Algorithms and Data Structures
LINKED LIST, STACKS AND QUEUES Saras M Srivastava, PGT – Comp. Sc. Kendriya Vidyalaya TengaValley.
Double Linked List Operations Dr. David Tsai 2010/4/12.
Singly Linked List BTECH, EE KAZIRANGA UNIVERSITY.
Data Structure Lecture-5
Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
Doubly-linked list library.
Ics202 Data Structures. hh tail head (b) LinkedList head tail Element datum next 3 Integer Element datum next 1 Integer Element datum next 4 Integer.
Linked Lists. Example We would like to keep a list of inventory records – but only as many as we need An array is a fixed size Instead – use a linked.
Computer Programming Link List (Insertion, Printing and Deletion functions) Lecture 23.
Linked Lists. Array Limitations Arrays have a fixed size that cannot be changed at run time What if your program had an array to store info regarding.
Introduction to C Programming CE Lecture 20 Insertion and Deletion with Linear Linked Lists.
The Template Class Chain Chain Linear list. Each element is stored in a node. Nodes are linked together using pointers.
Linked Lists A linked list is a series of connected nodes Each node contains at least –A piece of data (any type) –Pointer to the next node in the list.
CSE1303 Part A Data Structures and Algorithms Lecture A9 – Linked Lists.
UNIT-2. Singly Linked List Doubly Linked List Circular Linked List Representing Stack with Linked List. Representing Queue with Linked List.
UNIT 1 Data Structures Using C Linked List By Rohit Khokher Department of Computer Science, Vidya College of Engineering, Meerut, India.
Binary Trees Chapter Definition And Application Of Binary Trees Binary tree: a nonlinear linked list in which each node may point to 0, 1, or two.
Introduction to C Programming CE Lecture 24 Insertion and Deletion with Binary Search Trees.
1 Data Structures CSCI 132, Spring 2014 Lecture 20 Linked Lists.
LINKED LISTS Midwestern State University CMPS 1053 Dr. Ranette Halverson 1.
Copyright © 2012 Pearson Education, Inc. Chapter 20: Binary Trees.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 20: Binary Trees.
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.
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.
 Memory from the heap  Dynamic memory allocation using the new operator  Build a dynamic linked list  Another way of traversing a linked list 
Linked List.  Is a series of connected nodes, where each node is a data structure with data and pointer(s) Advantages over array implementation  Can.
Array 10 GB Hard Disk 2 GB 4 GB2 GB 3 GB DATA 4 GB Free Store data in the form of Array (Continuous memory locations) Solution-1: No Solution. Memory Insufficient.
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.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Linked Lists Chapter Introduction To The Linked List ADT Linked list: set of data structures (nodes) that contain references to other data structures.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 20: Binary Trees.
UNIT-II Topics to be covered Singly linked list Circular linked list
1 CSE 2341 Object Oriented Programming with C++ Note Set #18.
Section 2.6 Linked List StringLog ADT Implementation
Linked List Insert as a first node Insert as a last node
Linked List :: Basic Concepts
Lectures linked lists Chapter 6 of textbook
Linking in double direction
Linked List.
Problems with dynamic arrays
Linked lists.
Linked Lists.
Data Structures 7th Week
CHAPTER 12 LINKED LIST SRM-MCA.
CSC172 Data Structures Linked Lists (C version)
Chapter 20: Binary Trees.
8-1.
8-1.
Recursion.
List Objectives Describe a list
Chapter 21: Binary Trees.
ليست هاي پيوندي.
Stack and Queues Stack implementation using Array
Random inserting into a B+ Tree
Linked List Insert After
Review & Lab assignments
Data structure types. Linear and Non-Linear Data Structures: Linked lists, stacks and queues.
Linked List.
LINKED LIST.
Linked Lists Adapted from Dr. Mary Eberlein, UT Austin.
Philip Bernhard, PhD Spring 2018
CS148 Introduction to Programming II
Linked Lists.
Linked lists.
Linked List Insert After
Linked Lists.
Presentation transcript:

Linked List Insert as a first node Insert as a last node Delete first node Delete last node Insert after a node Insert before a node Traverse

Insert as a first node void insertf() { struct studinfo *newnode; newnode=(struct studinfo *) malloc(sizeof(struct studinfo)); printf("\nEnter a new record : marks and name "); scanf("%d%s",&newnode->marks,newnode->name); newnode->next=NULL; if(start==NULL) start = newnode; else newnode->next = start; }

Insert as a last node void insertl() { struct studinfo *newnode, *ptr; newnode=(struct studinfo *) malloc(sizeof(struct studinfo)); printf("\nEnter a new record : marks and name "); scanf("%d%s",&newnode->marks,newnode->name); newnode->next=NULL; if (start == NULL) start =newnode; else ptr =start; while (ptr->next != NULL) ptr= ptr->next; ptr->next = newnode; }

Delete first node void deletef() { struct studinfo *ptr; if (start == NULL) printf("\n List is empty"); return; } ptr=start; start=start->next; free(ptr);

Delete last node void deletel() { struct studinfo *ptr,*prevptr; ptr=start; if (ptr->next==NULL) start = NULL; else while(ptr->next!=NULL) prevptr=ptr; ptr=ptr->next; } prevptr->next =NULL; free(ptr);

Insert after a node void inserta() { int cnt=1, no; struct studinfo *ptr,*prevptr, *newnode; printf("\nEnter number ..."); scanf("%d",&no); ptr=start; while (cnt != no) ptr = ptr->next; cnt++; } newnode=(struct studinfo *) malloc(sizeof(struct studinfo)); printf("\nEnter a new record : marks and name "); scanf("%d%s",&newnode->marks,newnode->name); newnode->next =NULL; newnode->next = ptr->next; ptr->next = newnode;

Insert before a node void insertb() { int cnt=1, no; struct studinfo *ptr,*prevptr, *newnode; printf("\nEnter number ..."); scanf("%d",&no); ptr=start; if(no==1) insertf(); } else while(cnt !=no) prevptr=ptr; ptr = ptr->next; cnt++;

Continue… newnode=(struct studinfo *) malloc(sizeof(struct studinfo)); printf("\nEnter a new record : marks and name "); scanf("%d%s",&newnode->marks,newnode- >name); newnode->next=ptr; prevptr->next=newnode; }

Traverse void traverse() { struct studinfo *ptr; if (start == NULL) printf("\n List is empty"); return; } ptr= start; while (ptr !=NULL) printf("\nRecord: marks and name %d %s\n",ptr->marks, ptr->name); ptr = ptr->next; getch();