Last meeting..Doubly Linked List  InsertToFront  InsertToEnd  Search  DeleteNode.

Slides:



Advertisements
Similar presentations
Linked Lists Geletaw S..
Advertisements

Stacks, Queues, and Linked Lists
EENG212 Algorithms and Data Structures
Linked Lists.
Linked List Variations
CSE Lecture 12 – Linked Lists …
Data Structure Lecture-5
Doubly-linked list library.
Chapter 6 Structures By C. Shing ITEC Dept Radford University.
Chapter 17 Linked List Saurav Karmakar Spring 2007.
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 in C and C++ CS-2303, C-Term Linked Lists in C and C++ CS-2303 System Programming Concepts (Slides include materials from The C Programming.
More on Dynamic Memory Allocation Seokhee Jeon Department of Computer Engineering Kyung Hee University 1 Illustrations, examples, and text in the lecture.
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.
CS 206 Introduction to Computer Science II 09 / 17 / 2008 Instructor: Michael Eckmann.
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.
CS 206 Introduction to Computer Science II 09 / 15 / 2008 Instructor: Michael Eckmann.
Reference: Vinu V Das, Principles of Data Structures using C and C++
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 15: Linked data structures.
1 CSC 211 Data Structures Lecture 21 Dr. Iftikhar Azim Niaz 1.
CS 1031 Linked Lists Definition of Linked Lists Examples of Linked Lists Operations on Linked Lists Linked List as a Class Linked Lists as Implementations.
Linked Lists part 2 CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and Computer Science University.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 16. Linked Lists.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
Linked Lists Objects->Connected->by->Pointers. What is a Linked List? List: a collection Linked: any individual item points to another item to connect.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Data Structures Queues.
A Doubly Linked List prevnextdata There’s the need to access a list in reverse order header dnode.
Linked List Chapter Data Abstraction separates the logical properties of a data type from its implementation LOGICAL PROPERTIES – What are the.
© M. Gross, ETH Zürich, 2014 Informatik I für D-MAVT (FS 2014) Exercise 11 – Data Structures.
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,
LINKED LISTS Midwestern State University CMPS 1053 Dr. Ranette Halverson 1.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
CSCI387 Data Structure Fall Doubly Linked List Sep. 3, 2012 Sung Hee Park Computer Science Virginia State University.
Circular Linked List Singly Circular Linked List Doubly Circular Linked List.
Chapter 17: Linked Lists. Objectives In this chapter, you will: – Learn about linked lists – Learn the basic properties of linked lists – Explore insertion.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To introduce the basic concepts of linked lists ❏ To introduce the basic concepts.
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.  Is a series of connected nodes, where each node is a data structure with data and pointer(s) Advantages over array implementation  Can.
1 Linked List. Outline Introduction Insertion Description Deletion Description Basic Node Implementation Conclusion.
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.
Linked Lists Chapter Introduction To The Linked List ADT Linked list: set of data structures (nodes) that contain references to other data structures.
CS32 Discussion Section 1B Week 3 TA: Hao Yu (Cody)
Lists List Implementations. 2 Linked List Review Recall from CMSC 201 –“A linked list is a linear collection of self- referential structures, called nodes,
Linked Lists Data Structures and Algorithms CS 244 Brent M. Dingle, Ph.D. Department of Mathematics, Statistics, and Computer Science University of Wisconsin.
Prof. I. J. Chung Data Structure #4 Professor I. J. Chung.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
CPSC 252 Linked Lists III Page 1 Variations on Singly Linked Lists Inserting or deleting at the front of a list is different from at any other point in.
One implementation of the LIST ADT Insert new node before current and new node becomes current (assume new node created) node newNode = new node; head.
Review Deleting an Element from a Linked List Deletion involves:
Doubly Linked List Review - We are writing this code
UNIT-3 LINKED LIST.
CSE 143 Linked Lists [Chapter , 8.8] 3/30/98.
Linked List Variations
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.
A Doubly Linked List There’s the need to access a list in reverse order prev next data dnode header 1.
LINKED LISTS CSCD Linked Lists.
Linked Lists Chris Wright Winter 2006.
Doubly linked lists Idea: same as singly linked list, but each node also points to the previous: Can optionally also have a pointer to the tail, so we.
Tree A tree is a data structure in which each node is comprised of some data as well as node pointers to child nodes
Linked Lists Chapter 4.
Linked Lists Adapted from Dr. Mary Eberlein, UT Austin.
CS148 Introduction to Programming II
CS148 Introduction to Programming II
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
BY PROF. IRSHAD AHMAD LONE.
Linked Lists Dr. Jose Annunziato.
Presentation transcript:

Last meeting..Doubly Linked List  InsertToFront  InsertToEnd  Search  DeleteNode

InsertToFront  next of new node points to head  prev of node pointed by head points to new node  head pointer points to new node

InsertToEnd  next of tail points to new node  prev of tail points to node pointed by tail  tail pointer points to new node

With Doubly Linked List, we can traverse the nodes from tail to head headptr tailptr null null data prevnext

Create Node Code typedef struct node * nodeptr; nodeptr headptr,tailptr,newnode; struct node{ char * name; char * name; int age; int age; char * address; char * address; nodeptr prev, next; nodeptr prev, next;}; node * create_node(char in_name[],int in_age,char in_address[]) { node *t = new node; node *t = new node; t->name = new char[strlen(in_name)+1]; t->name = new char[strlen(in_name)+1]; t->address = new char[strlen(in_address)+1]; t->address = new char[strlen(in_address)+1]; t->age = in_age t->age = in_age strcpy(t->name,in_name); strcpy(t->name,in_name); strcpy(t->address,in_address); strcpy(t->address,in_address); t->next=NULL; t->next=NULL; t->prev=NULL; t->prev=NULL; } return t;

Circular Doubly Linked List Functions  Create Node  Insert in the Beginning  Insert in the End  Search A Node  Delete A Node

Insert a Node in the Front void InsertFront(nodeptr newnode) { if (headptr==NULL) tailptr=headptr; tailptr=headptr; headptr data newnode newnode->next = headptr; headptr->prev=newnode; headptr=newnode;} newnode->prev = tailptr; tailptr->next = newnode; tailptr

Inserting in Front: Reminders  prev of head should properly point to tail  head should point to the new node

Insert a Node in the End void InsertTail(nodeptr newnode) { if (tailptr==NULL) headptr=tailptr; headptr=tailptr; headptr data newnode tailptr tailptr->next =newnode; newnode->prev=tailptr; tailptr=newnode;headptr->prev=tailptr}

Insert Node at End:Reminders  next of tail should point to head  prev of head should point to tail

Bonus Question:  What if you do not have a tail pointer? How should you keep track the end of the list?

Searching…  is basically a sequential search..  inspect each data of the node if it is the key.  is similar to SearchNode of Linked list and Doubly Linked List  BUT, be cautious of the HEAD and the TAIL…this will create trouble

Searching a node nodeptr SearchNodeFromTail(char *key) {bool found; nodeptr cursor=tailptr; while (cursor!=NULL && !found) { if (strcmp(cursor->name,key)==0 found=true; found=true;else cursor=cursor->prev; cursor=cursor->prev; }; return cursor; } nodeptr SearchNodeFromHeadchar *key) {bool found; nodeptr cursor=headptr; while (cursor!=NULL && !found) { if (strcmp(cursor->name,key)==0 found=true; found=true;else cursor=cursor->next; cursor=cursor->next; }; return cursor; } For a bonus mark of 1, can you tell if there’s something wrong in these 2 functions? Discuss.

Deleting a node cursor Modify SearchNode 1. Declare a nodeptr prev; 2. Let prev follow cursor before it goes to next prev 8 null null

Modify SearchNode 1. Declare a nodeptr prev; 2. Let prev follow cursor before it goes to next 3. If the key is found; let next of prev point to next of cursor and previous of the next of cursor point to the previous of the cursor cursor prev 8 null null Deleting a node

Deleting a Node Modify SearchNode 1. Declare a nodeptr prev; 2. Let prev follow cursor before it goes to next 3. If the key is found; let next of prev point to next of cursor 4. Delete node pointed by cursor cursor prev 87

Applications of Linked List  database records  preliminary for advanced data structures such as binary trees, heaps,etc  computing power is based on linked list

Bonus Questions:  What type of linked list will you use for the BUSIT bus routes (From Transport Center to Sub-urbs)  How about for the Orbiter Bus Route?

We are done with linked lists  Next 2 weeks- Stacks and Queues  Applicatio of stacks and queus

Reminders  All supervised exercises (1,2,3 and 4?)for July and August are due on 16 th Aug 40%  1 st unsupervised exercise (practical laboratory test) will be on 18 th Aug (Fri) 60%