Data Structure Lecture-5

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.
Dynamic Allocation and Linked Lists. Dynamic memory allocation in C C uses the functions malloc() and free() to implement dynamic allocation. malloc is.
Stacks, Queues, and Linked Lists
Linked Lists.
CSCE 3110 Data Structures & Algorithm Analysis
Linked Lists: deleting...
CS 367 – Introduction to Data Structures
C and Data Structures Baojian Hua
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.
Singly Linked List BTECH, EE KAZIRANGA UNIVERSITY.
Computer Programming for Engineering Applications ECE 175 Intro to Programming.
Linked List Variations
CSCI2100B Linked List Jeffrey
Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
DS:Lab-1 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
Senem Kumova Metin Spring2009 STACKS AND QUEUES Chapter 10 in A Book on C.
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.
Chapter 17 Linked List Saurav Karmakar Spring 2007.
Senem Kumova Metin Spring2009 BINARY TREES && TREE TRAVERSALS Chapter 10 in A Book on C.
1 Queues and Lists. QUEUES Very similar to stacks The only difference between them is in the order in which elements are processed. A stack uses a last-in/first-out.
Computer Programming Link List (Insertion, Printing and Deletion functions) Lecture 23.
CS113 Introduction to C Instructor: Ioannis A. Vetsikas Lecture 7 : September 8.
Data Structures & Algorithms
Introduction to C Programming CE Lecture 20 Insertion and Deletion with Linear Linked Lists.
Introduction to C Programming CE Lecture 19 Linear Linked Lists.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Reference: Vinu V Das, Principles of Data Structures using C and C++
Implementation of Linked List For more notes and topics visit: eITnotes.com.
Lists 1. Introduction Data: A finite sequence of data items. Operations: Construction: Create an empty list Empty: Check if list is empty Insert: Add.
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
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,
Computer Programming for Engineering Applications ECE 175 Intro to Programming.
Lists (2). Circular Doubly-Linked Lists with Sentry Node Head.
Circular Linked List Singly Circular Linked List Doubly Circular Linked List.
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 
1 Midterm 1 on Friday February 12 Closed book, closed notes No computer can be used 50 minutes 4 questions Write a function Write program fragment Explain.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Linked Lists Outline Introduction Self-Referential Structures.
Doubly Linked List Exercises Sometimes it is useful to have a linked list with pointers to both the next and previous nodes. This is called a doubly linked.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Dynamic Allocation Review Structure and list processing
Linked List :: Basic Concepts
Lectures linked lists Chapter 6 of textbook
Doubly Linked List Review - We are writing this code
UNIT-3 LINKED LIST.
Data Structures and Algorithms
Linked List Variations
Algorithm for deleting a node from a singly linked list
Data Structures 7th Week
Lists.
Linked List Sudeshna Sarkar.
Programmazione I a.a. 2017/2018.
Lists.
Circularly Linked Lists
Doubly Linked Lists Lecture 21 Tue, Mar 21, 2006.
Review & Lab assignments
Data Structures and Algorithms
LINKED LIST.
Linked Lists.
Presentation transcript:

Data Structure Lecture-5 Prepared by: Shipra Shukla Assistant Professor Kaziranga University

Doubly Link List:Node data info: the user's data next, prev: the address of the next and previous node in the list .prev .data . next next prev

Syntax of node struct node { int data; struct node *next; struct node *prev; };

insert_at_begin void insert_at_begin(int item) { node *ptr; ptr=(node*)malloc (sizeof(node)); ptr->info=item; if( head==(node*)null) ptr->prev=ptr->next=(node*)null; head=tail=ptr; } else ptr->prev=(node*)null; ptr->next=head; head->prev=ptr; head=ptr;

insert_at_end void insert_at_end(int item) { node *ptr; ptr=(node*)malloc (sizeof(node)); ptr->info=item; if( tail==(node*)null) ptr->prev=ptr->next=(node*)null; head=tail=ptr; } else ptr->next=(node*)null; ptr->prev=tail; tail->next=ptr; tail=ptr;

Delete_at_begin void delete_at_begin() { node *ptr; if( head==(node*)nulll) return; else if(head->next==(node*)null) ptr=head; head=tail=(node*)null; } else head=head->next; head->prev=(node*)null; free(ptr);

Delete_at_end void delete_at_end() { node *ptr; if( tail==(node*)nulll) return; else if(tail->prev==(node*)null) ptr=tail; head=tail=(node*)null; } else tail=tail-> prev; tail->next=(node*)null; free(ptr);

Create Circular Doubly Linked list node* create_list() { node* head; head=allocate_node(); head->left= head->right=head; return (head); }

Insert a node in a Circular Doubly Linked list insert_cir(node*head, item) { node*ptr,*temp; int item; ptr=(node*) malloc (sizeof(node)); ptr->info=item; temp=head->right; head->right=ptr; ptr->left=head; ptr->right=temp; temp->left=ptr; return(head); }

Insert a node at end in a Circular Doubly Linked list insert_cir(node*head) { node*ptr,*temp; int item; ptr=(node*) malloc (sizeof(node)); ptr->info=item; temp=head->left; temp->right=ptr; ptr->left=temp; ptr->right=head; head->left=ptr; return(head); }

Delete a node at begin in a Circular Doubly Linked list del_beg(node*head) { node*temp; if(head->right==head) printf(“List is empty”); return; } else temp=head->right; printf(“deleted element is=%d”,temp->info); head->right=temp->right; temp->right=temp->left=head; free(temp); return(head);

Delete a node at end in a Circular Doubly Linked list del_end(node*head) { node*temp; if(head->right==head) printf(“List is empty”); return; } else temp=head->left; printf(“deleted element is=%d”,temp->info); head->left=temp->left; free(temp); return(head);