Singly Linked List BTECH, EE KAZIRANGA UNIVERSITY.

Slides:



Advertisements
Similar presentations
Incomplete Structs struct B; struct A { struct B * partner; // other declarations… }; struct B { struct A * partner; // other declarations… };
Advertisements

Linked List Alternate approach to maintaining an array of elements Rather than allocating one large group of elements, allocate elements as needed Q: how.
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.
Stacks, Queues, and Linked Lists
Linked Lists.
DATA STRUCTURES USING C++ Chapter 5
Linked Lists Linked Lists Representation Traversing a Linked List
LINKED LIST, STACKS AND QUEUES Saras M Srivastava, PGT – Comp. Sc. Kendriya Vidyalaya TengaValley.
Fall 2005 Data Structure Linked List – Single Linked List.
Data Structures Linked Lists Linked List Basics. Array Disadvantages Arrays, although easy to understand have lots of disadvantages Contiguous Memory.
Double Linked List Operations Dr. David Tsai 2010/4/12.
Linked Lists CSE 2451 Matt Boggus. Dynamic memory reminder Allocate memory during run-time malloc() and calloc() – return a void pointer to memory or.
418115: II. Linked List A linked list can be thought of a chain of linked list elements. A linked list element contains a single data item, and contains.
CSCE 3110 Data Structures & Algorithm Analysis
LIST PROCESSING.
Computer Programming for Engineering Applications ECE 175 Intro to Programming.
Linked List Variations
CSCI2100B Linked List Jeffrey
Dynamic memory allocation
Data Structure Lecture-5
Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
Senem Kumova Metin Spring2009 STACKS AND QUEUES Chapter 10 in A Book on C.
Dynamic Memory Allocation in C.  What is Memory What is Memory  Memory Allocation in C Memory Allocation in C  Difference b\w static memory allocation.
Doubly-linked list library.
Data Structures: Doubly Linked List1 Doubly linked list l The linear linked list is accessed from the first node each time we want to insert or delete.
C Intro.
Senem Kumova Metin Spring2009 BINARY TREES && TREE TRAVERSALS Chapter 10 in A Book on C.
Computer Programming Link List (Insertion, Printing and Deletion functions) Lecture 23.
Growing Arrays in C By: Victoria Tielebein CS 265- Spring 2011.
Memory allocation CSE 2451 Matt Boggus. sizeof The sizeof unary operator will return the number of bytes reserved for a variable or data type. Determine:
Introduction to C Programming CE Lecture 20 Insertion and Deletion with Linear Linked Lists.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
Dynamic Allocation and Linked Lists. Dynamic memory allocation in C C uses the functions malloc() and free() to implement dynamic allocation. malloc is.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
CGS 3460 Pointer n To hold the location of another variable n Declaration: la type and a name with an asterisk lE.g. int *ptr; n Assigning a value lptr.
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.
UNIT 1 Data Structures Using C Linked List By Rohit Khokher Department of Computer Science, Vidya College of Engineering, Meerut, India.
Lists 1. Introduction Data: A finite sequence of data items. Operations: Construction: Create an empty list Empty: Check if list is empty Insert: Add.
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.
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.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Elementary Data Structures Linked Lists Linked Lists Dale.
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.
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.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Linked Lists Outline Introduction Self-Referential Structures.
Linked Lists Chapter Introduction To The Linked List ADT Linked list: set of data structures (nodes) that contain references to other data structures.
  A linked list is a collection of components called nodes  Every node (except the last one) contains the address of the next node  The address of.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Chapter 12 – Data Structures
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:
Prepared by, Jesmin Akhter, Lecturer, IIT, JU
Lecture - 6 On Data Structures
UNIT-3 LINKED LIST.
Linked lists.
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.
Lists.
Recursion.
Lists.
Review & Lab assignments
Chapter 17: Linked Lists.
Linked lists.
Presentation transcript:

Singly Linked List BTECH, EE KAZIRANGA UNIVERSITY

Singly Linked List A Singly Linked List is one in which all nodes are linked together in some sequential manner. A Singly Linked List is a Dynamic data structure. It can grow and shrink depending on the operations performed on it START

Syntax of Node struct Node { int num; struct node *ptr;//Pointer to Node }

INSERTION in Singly Linked List Inserting a Node at the beginning Void insert_begin( int item ) {node *ptr; ptr = (node *)malloc(sizeof(node)); ptr -> info = item; if(start == NULL) {ptr->next = NULL; } else {ptr->next = start; } start = ptr; }

Inserting a Node at the end Void insert_end( int item ) {node *ptr, *loc; ptr = (node *)malloc(sizeof(node)); ptr -> info = item; ptr -> next = NULL; if(start == NULL) {start = ptr; } else {loc=start; while(loc->next != NULL) {loc = loc->next;} loc-next=ptr; }

Inserting a Node at the specified position Void insert_spe( NODE *start, int item ) {node *ptr, *temp; int loc, k; if(start==NULL) {printf(Empty List); return;} for(k=1, temp=start ; k<loc ; k++) { temp=temp->next; if(temp==NULL) {printf(Node in List is less than the location); return; } ptr = (node *)malloc(sizeof(node)); ptr -> info = item; ptr -> next = temp->next; temp->next = ptr; }

DELETION in Singly Linked List Deletion of the First Node void delete_begin() {node *ptr; if(start == NULL) { printf(Empty List); return;} else {ptr=start; start=start->next; printf(Element deleted is : %d,ptr->num); free(ptr); }

Deletion of the Last Node void delete_end() {node *ptr, *loc; if(start == NULL) {printf(Empty List); return;} else if(start->next==NULL) {ptr=start; start=NULL; printf(Element Deleted : %d,ptr->num); free(ptr);} else {loc=start; ptr=start->next; while(ptr->next != NULL) {loc=ptr; ptr=ptr->next;} loc->next=NULL; printf(Element Deleted : %d,ptr->num); free(ptr); }

Deletion of the Node at a specified position void delete_specific() {node *ptr, *temp; Int i,loc; printf(Enter the position where the node is to be deleted : ); scanf(%d,&loc); if(start == NULL) {printf(Empty List); return;} else {ptr=start; for(i=1;i<=loc;i++) {temp = ptr; ptr = ptr -> next; if(ptr==NULL) {printf(Node in List is less than the location); return; } printf(Number deleted is : %d, ptr->num ); temp->next=ptr->next; free(ptr); }

ADVANTAGES AND DISADVANTAGES Advantages Accessing of a node in the forward direction is easier. Insertion and Deletion of nodes are easier Disadvantages Accessing the preceding node of a current node is not possible as there is no backward traversal. Accessing a node is time consuming