Circular Linked List Singly Circular Linked List Doubly Circular Linked List.

Slides:



Advertisements
Similar presentations
Stacks, Queues, and Linked Lists
Advertisements

Chapter 24 Lists, Stacks, and Queues
Chapter 3 – Lists A list is just what the name implies, a finite, ordered sequence of items. Order indicates each item has a position. A list of size 0.
Data Structure HKOI training /4/2010 So Pak Yeung.
The Stack Data Structure. Classic structure What is a Stack? An abstract data type in which accesses are made at only one end Last In First Out (LIFO)
CSE Lecture 12 – Linked Lists …
Data Structure Lecture-5
Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
Doubly-linked list library.
Chapter 17 Linked List Saurav Karmakar Spring 2007.
Lists List L = x0 x1 x2 x3 … xn-1 n = # elements
 A queue is a waiting line…….  It’s in daily life:-  A line of persons waiting to check out at a supermarket.  A line of persons waiting.
CS Data Structures II Review COSC 2006 April 14, 2017
C Programming : Elementary Data Structures 2009/04/22 Jaemin
Abstract Data Types (ADT) Collection –An object that can hold a list of other objects Homogeneous Collection –Contains elements all of the same type –Example:
Chapter 13 Pointers and Linked Lists. Nodes and Linked Lists Linked list: A sequence of nodes in which each node is linked or connected to the node preceding.
Stack and Queue Dr. Bernard Chen Ph.D. University of Central Arkansas.
Stacks. COMP104 Slide 2 Stacks * A stack, S, is a data structure that supports: n push(x) make x the top element in stack S n Pop Remove the top item.
1 Chapter 24 Lists Stacks and Queues. 2 Objectives F To design list with interface and abstract class (§24.2). F To design and implement a dynamic list.
Tirgul 3 Subjects of this Tirgul: Linked Lists Doubly-Linked Lists Sparse Matrices Stack Queue.
Stacks CS-240 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed in reverse.
Stacks CS-240 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed in reverse.
Stacks CS-240 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed in reverse.
Fall 2007CS 2251 Stacks Chapter 5. Fall 2007CS 2252 Chapter Objectives To learn about the stack data type and how to use its four methods: push, pop,
Fall 2007CS 2251 Stacks Chapter 5. Fall 2007CS 2252 Chapter Objectives To learn about the stack data type and how to use its four methods: push, pop,
Summary of lectures (1 to 11)
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 26 Implementing Lists, Stacks,
Stacks CS-240 & CS-341 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed.
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
Chapter 7 Stacks II CS Data Structures I COSC 2006
Comp 245 Data Structures Stacks. What is a Stack? A LIFO (last in, first out) structure Access (storage or retrieval) may only take place at the TOP NO.
Review 1 Introduction Representation of Linear Array In Memory Operations on linear Arrays Traverse Insert Delete Example.
Reference: Vinu V Das, Principles of Data Structures using C and C++
Lists ADT (brief intro):  Abstract Data Type  A DESCRIPTION of a data type  The data type can be anything: lists, sets, trees, stacks, etc.  What.
Data Structures. The Stack: Definition A stack is an ordered collection of items into which new items may be inserted and from which items may be deleted.
1 Chapter 7 Stacks and Queues. 2 Stack ADT Recall that ADT is abstract data type, a set of data and a set of operations that act upon the data. In a stack,
Data Structures (part 2). Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that last ‘rush’
Lists, Stacks and Queues in C Yang Zhengwei CSCI2100B Data Structures Tutorial 4.
EASTERN MEDITERRANEAN UNIVERSITY Stacks EENG212 –Algorithms and Data Structures.
Stacks Ellen Walker CPSC 201 Data Structures Hiram College.
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
Linear Data Structures
2005MEE Software Engineering Lecture 7 –Stacks, Queues.
Fall 2006 METU EEEEE 441 S. Ece (GURAN) SCH MIDT EE 441 Data Structures Lecture 6 Stacks and Queues.
Copyright © Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by Tony.
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.
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.
“The desire for safety stands against every great and noble enterprise.” – Tacitus Thought for the Day.
Computer Science Department Data Structure and Algorithms Lecture 3 Stacks.
Chapter 4 ADTs Stack and Queue. 4-2 Formal ADT Specifications The Java interface construct lets us collect together method interfaces into a syntactic.
Click to edit Master text styles Stacks Data Structure.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
List Structures What is a list? A homogeneous collection of elements with a linear relationship between the elements linear relationship - each element.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part R2. Elementary Data Structures.
Lectures linked lists Chapter 6 of textbook
Doubly Linked List Review - We are writing this code
Data Structures and Algorithms
Dr. Bernard Chen Ph.D. University of Central Arkansas
Stack and Queue APURBO DATTA.
Stack Lesson xx   This module shows you the basic elements of a type of linked list called a stack.
Pointers and Linked Lists
Data Structures and Database Applications Stacks in C#
Queues FIFO Enqueue Dequeue Peek.
Data Structures and Algorithms
Stacks and Queues Prof. Michael Tsai 2017/02/21.
Stacks CS-240 Dick Steflik.
Stacks LIFO C C B B B B A A A A A Push (A) Push (B) Push (C) Pop Pop.
LAB#3 Stacks Nora Albabtin nora albabtin.
LINEAR DATA STRUCTURES
Presentation transcript:

Circular Linked List Singly Circular Linked List Doubly Circular Linked List

Circular Linked List void make(int a) { ptr=new LIST; if (!head) head=ptr; else rear->next=ptr; ptr->dann=a; rear=ptr; rear->next=head; }

Doubly Linked List struct NDD { int val; NDD * next; NDD * prev; }; NDD *beg=NULL, *end=NULL;

List Building void make(int a) { NDD *rex; rex=new NDD; rex->val=a; if (!beg) beg=rex; else end->next=rex; rex->prev=end; end=rex; end->next=NULL; } // The new rex points to a NDD struct // Store data in the new node. // If the list is empty, the rex pointer // changes the beg pointer // Else change end.next field from NULL to point // to the new node // Set rex.prev field equal to the prev (end) node // Set end to point to the new node // set end.next field equal to a null pointer

List Building void make(int a) { NDD *rex; rex=new NDD; rex->val=a; if (!beg) beg=rex; else end->next=rex; rex->prev=end; end=rex; end->next=NULL; } prevnext rex 5 beg NULL prevnext rex 3 end NULL prevnext rex 9 NULL

Deleting a node 1.We locate the previous node using the previous field. 2.We make the next field of this node point to the node following the one in the cursor position rex: rex->prev->next=rex->next; 3.Then we make the previous field of this following node point to the node preceding the one in the cursor position rex: rex->next->prev=rex->prev; 4.The list node pointed to by the cursor rex becomes useless and should be deleted: delete rex;

Deleting a node NDD rex=beg; while(rex!=NULL && rex->val!=ad) rex=rex->next; if (rex!=NULL) { rex->prev->next=rex->next; rex->next->prev=rex->prev; delete rex; } prev3nextprev6nextprev-9nextprev11nextprev4next beg end NULL rex

Traversing the list NDD *rex=beg; while (rex!=NULL) rex=rex->next; NDD *rex=end; while (rex!=NULL) rex=rex->prev;

Stacks LIFO A Push (A) A B Push (B) C Push (C) A B C A B Pop A B

Array-based implementation array A; the variable top (-1…(capacity-1)); the capacity.

struct STACK { int dann; STACK *prev; }; STACK *top=NULL; Linked List-based implementation

Operations void push(int a) {STACK *q; q=new STACK; q->prev=top; q->dann=a; top=q; } // new q points to the stack struct // set q.prev field to the top // (add a new node to the top of the stack) // store data in the new node // set top to point to the new node Push a new element onto the stack prev q NULL 1 top prev q 2 q 3

Remove the top element from the stack int pop(void) {STACK *q; int temp=-1; if (!top) cout << "\nEmpty"; else {temp=top->dann; q=top->prev; delete top; top=q; } return temp; } // store the top node data // the q holds the position of the // next node in the stack // the top is deleted // set top equal to the q prev NULL 1 top prev 2 q 3 4 temp=4

Return the top element value int peek (void) {int temp; if (!top) { cout << "\nEmpty"; return -1; } temp=top->dann; return temp; } prev NULL 1 top prev temp=4

Destroying the stack void clear (void) {STACK *q; while (top) { q=top->prev; delete top; top=q; } // while the top pointer is not equal to the NULL // the q pointer is used to hold the position // of the next node in the stack // the top is deleted // set top equal to the q prev NULL 1 top prev q

Stack applications Reverse a word. Palindrome strings “A man, a plan, a canal—Panama!” “Able I was ere, I saw Elba.” “Won ton? Not now!” “Madam, I’m Adam.” “Eve.”

struct NDD { int val; NDD * next; NDD * prev; }; NDD *beg=NULL, *end=NULL; void make(int a) { NDD *rex; rex=new NDD; rex->val=a; if (!beg) beg=rex; else end->next=rex; rex->prev=end; end=rex; end->next=NULL; } NDD rex=beg; while(rex!=NULL && rex->val!=ad) rex=rex->next; if (rex!=NULL) { rex->prev->next=rex->next; rex->next->prev=rex->prev; delete rex; } NDD *rex=beg; while (rex!=NULL) rex=rex->next; NDD *rex=end; while (rex!=NULL) rex=rex->prev;