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,

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

Stacks, Queues, and Linked Lists
Linked Lists.
DATA STRUCTURES USING C++ Chapter 5
Linked Lists Linked Lists Representation Traversing a Linked List
Data Structures Using C++
CHP-5 LinkedList.
Singly Linked List BTECH, EE KAZIRANGA UNIVERSITY.
1 DATA STRUCTURES. 2 LINKED LIST 3 PROS Dynamic in nature, so grow and shrink in size during execution Efficient memory utilization Insertion can be.
Data Structure Lecture-5
Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
Review Learn about linked lists
Data Structures: A Pseudocode Approach with C
Data Structures & Algorithms
Queue using an array. .head.tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
Main Index Contents 11 Main Index Contents Abstract Model of a List Obj. Abstract Model of a List Obj. Insertion into a List Insertion into a List Linked.
C++ Programming: Program Design Including Data Structures, Fifth Edition Chapter 17: Linked Lists.
Variations of Linked Lists CS 308 – Data Structures.
Reference: Vinu V Das, Principles of Data Structures using C and C++
Implementation of Linked List For more notes and topics visit: eITnotes.com.
Data Structures Using Java1 Chapter 4 Linked Lists.
Chapter 1 Object Oriented Programming. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
Department of Computer Science Data Structures Using C++ 2E Chapter 5 Linked Lists.
Linked List by Chapter 5 Linked List by
Data Structures Using C++1 Chapter 5 Linked Lists.
1 Linked Lists (Lec 6). 2  Introduction  Singly Linked Lists  Circularly Linked Lists  Doubly Linked Lists  Multiply Linked Lists  Applications.
Copyright © 2012 Pearson Education, Inc. Chapter 20: Binary Trees.
Data Structures Doubly and Circular Lists Lecture 07: Linked Lists
Linear Data Structures
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Elementary Data Structures Linked Lists Linked Lists Dale.
1 What is a Circular Linked List? l A circular linked list is a list in which every node has a successor; the “last” element is succeeded by the “first”
Circular Linked List Singly Circular Linked List Doubly Circular Linked List.
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
Chapter 17: Linked Lists. Objectives In this chapter, you will: – Learn about linked lists – Learn the basic properties of linked lists – Explore insertion.
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.
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.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 20: Binary Trees.
  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 16: Linked Lists.
Unit – I Lists.
C++ Programming:. Program Design Including
Data Structure By Amee Trivedi.
Lectures linked lists Chapter 6 of textbook
Program based on queue & their operations for an application
Review Deleting an Element from a Linked List Deletion involves:
Sequences 6/18/2018 8:51 PM C201: Linked List.
Prepared by, Jesmin Akhter, Lecturer, IIT, JU
Lecture - 6 On Data Structures
UNIT-3 LINKED LIST.
Linked-list.
Linked lists.
Data Structures Interview / VIVA Questions and Answers
Sequences 9/18/ :20 PM C201: Linked List.
Chapter 20: Binary Trees.
Programmazione I a.a. 2017/2018.
LINKED LISTS CSCD Linked Lists.
Chapter 21: Binary Trees.
Dummy Nodes, Doubly Linked Lists and Circular Linked Lists
Doubly Linked Lists Lecture 21 Tue, Mar 21, 2006.
Chapter 17: Linked Lists.
Linked Lists.
Linked lists.
Chapter 9 Linked Lists.
LINEAR DATA STRUCTURES
Presentation transcript:

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, the last node contains a pointer to the first node of the list. We can have a circular singly listed list as well as circular doubly linked list. We can have a circular singly listed list as well as circular doubly linked list. While traversing a circular linked list, we can begin at any node and traverse the list in any direction forward or backward until we reach the same node where we had started. While traversing a circular linked list, we can begin at any node and traverse the list in any direction forward or backward until we reach the same node where we had started. Thus, a circular linked list has no beginning and no ending. Thus, a circular linked list has no beginning and no ending FIRST

Insert a new node at the beginning of circular linked list Function INSERTBEG (X, FIRST) : Given X, a new element, and FIRST, a pointer to the first element of a circular linked list whose typical node contains INFO and LINK fields, this functions inserts X. AVAIL is a pointer to the top element of the availability stack, NEW and TEMP are temporary pointer variables. It is required that X precedes the node whose address is given by FIRST. 1. [Underflow?] 1. If AVAIL = NULL 2. then Write (‘STACK UNDERFLOW’) 1. Return (FIRST) 2. [Obtain address of next free node] 1. NEXT  AVAIL 3. [Remove free node from availability stack] 1. AVAIL  LINK (AVAIL) 4. [Initialize fields of new node] 1. INFO (NEW)  X 5.[Is list empty?] 1.If FIRST = NULL 2.Then LINK(NEW)  NEW 1.Return (NEW) 6.[Search for the first node] 1.TEMP  FIRST 7.[Search for the end of the list] 1.Repeat while LINK(TEMP) != FIRST 1.TEMP  LINK(TEMP) 8.[Set LINK field of new node] 1.LINK (NEW)  FIRST

9. [Set LINK field of last node] 1. LINK (TEMP)  NEW 10. [Return first node pointer] 1. Return (NEW) FIRST, TEMP FIRST TEMP Insert a new node at the beginning of circular linked list

Insert a new node at the end of circular linked list Function INSERTEND (X, FIRST) : Given X, a new element, and FIRST, a pointer to the first element of a circular linked list whose typical node contains INFO and LINK fields, this functions inserts X. AVAIL is a pointer to the top element of the availability stack, NEW and TEMP are temporary pointer variables. It is required that X be inserted at the end of the list. 1. [Underflow?] 1. If AVAIL = NULL 2. then Write (‘STACK UNDERFLOW’) 1. Return (FIRST) 2. [Obtain address of next free node] 1. NEXT  AVAIL 3. [Remove free node from availability stack] 1. AVAIL  LINK (AVAIL) 4. [Initialize fields of new node] 1. INFO (NEW)  X 2. LINK (NEW)  FIRST 5.[Is list empty?] 1.If FIRST = NULL 1.Return (NEW) 6.[Search for the last node] 1.TEMP  FIRST 7.[Search for the end of the list] 1.Repeat while LINK(TEMP) != FIRST 1.TEMP  LINK(TEMP) 8.[Set LINK field of new node] 1.LINK (TEMP)  NEW 9.[Return FIRST node pointer] 1.Return (FIRST)

Delete a node from the beginning of circular linked list Procedure DELETEBEG (FIRST) : Given FIRST, a pointer to the first element of a circular linked list whose typical node contains INFO and LINK fields, this procedure deletes the node from the beginning of the circular linked list. TEMP is used to find the desired node. 1. [Empty list?] 1. If FIRST = NULL 2. then Write (‘UNDERFLOW’) 1. Return 2. [Initialize search for first node] 1. TEMP  FIRST 3. [Search for the end of list] 1. Repeat while LINK (TEMP) != FIRST 1. TEMP  LINK (TEMP) 4. [Delete the first node] 1. LINK (TEMP)  LINK (FIRST) 5.[Make next node to be first?] 1.If FIRST  LINK ( TEMP) 6.[Return node to availability stack] 1.LINK (FIRST)  AVAIL 2.AVAIL  FIRST 3.Return

Delete a node from the end of circular linked list Procedure DELETEEND (FIRST) : Given FIRST, a pointer to the first element of a circular linked list whose typical node contains INFO and LINK fields, this procedure deletes the node from the end of the circular linked list. TEMP is used to find the desired node. PRED keeps track of predecessor of TEMP. 1. [Empty list?] 1. If FIRST = NULL 2. then Write (‘UNDERFLOW’) 1. Return 2. [Initialize search for first node] 1. TEMP  FIRST 3. [Find last node] 1. Repeat thru Step 5 while LINK (TEMP) != FIRST 4. [Update predecessor marker] 1. PRED  TEMP 5.[Move to next node] 1.TEMP  LINK ( TEMP) 6.[Delete last node] 1.LINK (PRED)  FIRST 7.[Return node to availability stack] 1.LINK (TEMP)  AVAIL 2.AVAIL  TEMP 3.Return

ANY QUESTIONS?? 13