Sequences 9/18/2018 12:20 PM C201: Linked List.

Slides:



Advertisements
Similar presentations
Pointers.
Advertisements

Linked Lists Mohammed Almashat CS /03/2006.
Linked Lists.
DATA STRUCTURES USING C++ Chapter 5
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.
Doubly linked list concept Node structure Insertion sort Insertion sort program with a doubly linked list.
Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
David Notkin Autumn 2009 CSE303 Lecture 13 This space for rent.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
Week 3 - Wednesday.  What did we talk about last time?  Started linked lists.
Data Structures Using C++ 2E
Complex Structures Nested Structures Self referential structures A structure may have Data variables Internal structures/unions Pointer links Function.
1 Chapter 16-1 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion.
Binary Trees Chapter Definition And Application Of Binary Trees Binary tree: a nonlinear linked list in which each node may point to 0, 1, or two.
© M. Gross, ETH Zürich, 2014 Informatik I für D-MAVT (FS 2014) Exercise 12 – Data Structures – Trees Sorting Algorithms.
Department of Computer Science Data Structures Using C++ 2E Chapter 5 Linked Lists.
Slide 1 Linked Data Structures. Slide 2 Learning Objectives  Nodes and Linked Lists  Creating, searching  Linked List Applications  Stacks, queues.
Review 1 Polish Notation Prefix Infix Postfix Precedence of Operators Converting Infix to Postfix Evaluating Postfix.
ENEE150 – 0102 ANDREW GOFFIN Linked List/Project 3.
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
 Head pointer  Last node  Build a complete linked list  Node deletion  Node insertion  Helpful hints.
Copyright © 2012 Pearson Education, Inc. Chapter 20: Binary Trees.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 20: Binary Trees.
Week 4 - Friday.  What did we talk about last time?  Continued doubly linked list implementation  Linked lists with iterators.
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: 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:
1 Linked List. Outline Introduction Insertion Description Deletion Description Basic Node Implementation Conclusion.
Linked Lists Chapter Introduction To The Linked List ADT Linked list: set of data structures (nodes) that contain references to other data structures.
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.
 Review building a complete linked list  List traversal in main ( )  List traversal using a function.
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.
1 Linked List. List vs Arrays Two built-in data structures that can be used to organize data, or to create other data structures: Lists Arrays.
C++ Programming:. Program Design Including
COMP 53 – Week Eight Linked Lists.
Pointers and Linked Lists
Pointers and Linked Lists
Lectures linked lists Chapter 6 of textbook
UNIT – I Linked Lists.
Review Deleting an Element from a Linked List Deletion involves:
CS2006- Data Structures I Chapter 5 Linked Lists I.
Sequences 6/18/2018 8:51 PM C201: Linked List.
Exercise 1 From Lec80b-Ponter.ppt.
UNIT-3 LINKED LIST.
Chapter 4 Linked Lists.
Linked lists.
Linked lists Motivation: we can make arrays, but their functionality is slightly limited and can be difficult to work with Biggest issue: size management.
CSCE 210 Data Structures and Algorithms
Chapter 20: Binary Trees.
Stack Lesson xx   This module shows you the basic elements of a type of linked list called a stack.
Prof. Neary Adapted from slides by Dr. Katherine Gibson
Recursion.
Chapter 16-2 Linked Structures
Chapter 21: Binary Trees.
CS 2308 Exam II Review.
CS 2308 Exam II Review.
CS 2308 Exam II Review.
[Chapter 4; Chapter 6, pp ] CSC 143 Linked Lists [Chapter 4; Chapter 6, pp ]
Review & Lab assignments
Linked Lists Chapter 4.
Chapter 17: Linked Lists.
Chapter 16 Linked Structures
CS148 Introduction to Programming II
Chapter 20: Binary Trees.
CS148 Introduction to Programming II
Linked lists.
Linked Lists.
Presentation transcript:

Sequences 9/18/2018 12:20 PM C201: Linked List

Learning Objectives Nodes and Linked Lists Operations on Linked List Insert Search Remove

Nodes and Linked Lists Why do we need linked list? Linked list Simple example of "dynamic data structure" Composed of nodes Each "node" is variable of struct that’s dynamically created with new Nodes also contain pointers to other nodes Provide "links"

Node Definition struct node { int value; node * next; }; value next

Node and Linked list struct node { int value; node * next; }; An incomplete linked list value next value next value next

Node and Linked list struct node { int value; node * next; }; ? We need something to indicate the end of the list value next value next value next ?

End Marker Use NULL for next pointer (if next==NULL) Indicates no further "links" after this node Provide end marker for linked list

Node and Linked list struct node { int value; node * next; }; value NULL

Node and Linked list struct node { int value; node * next; }; ? We still need a handle to access the nodes the list ? value next value next value next NULL

Head Pointer Node * head; A simple pointer to Node Set to point to 1st node in list head is used to "maintain" start of list Also used as argument to functions value next head node

Node and Linked list struct node { int value; node * next; }; value head value next value next value next NULL

Node and Linked list struct node { int value; node * next; }; value head value next value next value next 202 101 303 NULL

Data Fields in Node struct student { int ID; double GPA; student * next; };

Data Fields in Node struct student { int ID; double GPA; student * next; }; head ID GPA next ID GPA next ID GPA next 1001 3.5 3003 3.3 2002 2.5 NULL

How to Create a Linked List

How to Create a Linked List 0. Define the node

How to Create a Linked List 0. Define the node struct node { int value; node * next; };

How to Create a Linked List 1. Create a head struct node { int value; node * next; };

How to Create a Linked List 1. Create a head node * head = NULL; struct node { int value; node * next; }; head NULL

How to Create a Linked List 2. Create an instance of node struct node { int value; node * next; }; head NULL

How to Create a Linked List 2. Create an instance of node node * n= new node; struct node { int value; node * next; }; n head value next NULL

How to Create a Linked List 2. Dynamically create an instance of node n->value = 303; n->next = NULL; struct node { int value; node * next; }; n head value next 303 NULL NULL

How to Create a Linked List 3. Insert the node to (the head of) the list n->next = head; head = n; struct node { int value; node * next; }; n head value next 303 NULL NULL

How to Create a Linked List 3. Insert the node to the list struct node { int value; node * next; }; n head value next 303 NULL

How to Create a Linked List 3. Insert the node to the list struct node { int value; node * next; }; head value next 303 NULL

How to Create a Linked List 4. Repeat Step 2 and Step 3 to create and insert all nodes struct node { int value; node * next; }; head value next 303 NULL

How to Create a Linked List 4. Repeat Step 2 and Step 3 to create and insert all nodes node * n= new node; n->value = 101; n->next = NULL; struct node { int value; node * next; }; n value next head 101 NULL value next 303 NULL

How to Create a Linked List 4. Repeat Step 2 and Step 3 to create and insert all nodes n->next = head; head = n; struct node { int value; node * next; }; n value next head 101 NULL value next 303 NULL

How to Create a Linked List 4. Repeat Step 2 and Step 3 to create and insert all nodes n->next = head; head = n; struct node { int value; node * next; }; n value next head 101 value next 303 NULL

How to Create a Linked List 4. Repeat Step 2 and Step 3 to create and insert all nodes n->next = head; head = n; struct node { int value; node * next; }; n value next head 101 value next 303 NULL

How to Create a Linked List 4. Repeat Step 2 and Step 3 to create and insert all nodes struct node { int value; node * next; }; value next head 101 value next 303 NULL

How to Create a Linked List 4. Repeat Step 2 and Step 3 to create and insert all nodes struct node { int value; node * next; }; head value next value next 101 303 NULL

How to Create a Linked List 4. Repeat Step 2 and Step 3 to create and insert all nodes node * n= new node; n->value = 101; n->next = NULL; struct node { int value; node * next; }; n value next 101 NULL head value next value next 101 303 NULL

How to Create a Linked List 4. Repeat Step 2 and Step 3 to create and insert all nodes n->next = head; head = n; ; struct node { int value; node * next; }; n value next 101 NULL head value next value next 101 303 NULL

How to Create a Linked List 4. Repeat Step 2 and Step 3 to create and insert all nodes n->next = head; head = n; struct node { int value; node * next; }; n value next 101 head value next value next 101 303 NULL

How to Create a Linked List 4. Repeat Step 2 and Step 3 to create and insert all nodes n->next = head; head = n; struct node { int value; node * next; }; n value next 101 head value next value next 101 303 NULL

How to Create a Linked List 4. Repeat Step 2 and Step 3 to create and insert all nodes struct node { int value; node * next; }; value next 101 head value next value next 101 303 NULL

How to Create a Linked List 5. A linked list is created struct node { int value; node * next; }; head value next value next value next 101 101 303 NULL

Node Access head->value = 404; 202 101 303 NULL head value next

Node Access head value next value next value next 404 101 303 NULL

Node Access cout << head->next->value; //What will be displayed head value next value next value next 404 101 303 NULL

Node Access head->next->next->value=505; 404 101 303 NULL

Node Access head value next value next value next 404 101 505 NULL

Node Access node * temp = head; While (temp != NULL) { cout << temp->value; // access data fields temp = temp->next; } head value next value next value next 404 101 505 NULL

Node Access node * temp = head; While (temp != NULL) { cout << temp->value; // access data fields temp = temp->next; } head value next value next value next 404 101 505 NULL temp

Node Access node * temp = head; While (temp != NULL) { cout << temp->value; // access data fields temp = temp->next; } head value next value next value next 404 101 505 NULL temp

Node Access node * temp = head; While (temp != NULL) { cout << temp->value; // access data fields temp = temp->next; } head value next value next value next 404 101 505 NULL temp

Node Access node * temp = head; While (temp != NULL) { cout << temp->value; // access data fields temp = temp->next; } head value next value next value next 404 101 505 NULL temp

Node Access node * temp = head; While (temp != NULL) { cout << temp->value; // access data fields temp = temp->next; } head value next value next value next 404 101 505 NULL temp

Node Access node * temp = head; While (temp != NULL) { cout << temp->value; // access data fields temp = temp->next; } head value next value next value next 404 101 505 NULL temp

Node Access node * temp = head; While (temp != NULL) { cout << temp->value; // access data fields temp = temp->next; } head value next value next value next 404 101 505 NULL temp

Node Access node * temp = head; While (temp != NULL) { cout << temp->value; // access data fields temp = temp->next; } head value next value next value next 404 101 505 NULL temp

Node Access node * temp = head; While (temp != NULL) { cout << temp->value; // access data fields temp = temp->next; } head value next value next value next 404 101 505 NULL temp

Node Access node * temp = head; While (temp != NULL) { cout << temp->value; // access data fields temp = temp->next; } head value next value next value next 404 101 505 NULL temp

Node Access node * temp = head; While (temp != NULL) { cout << temp->value; // access data fields temp = temp->next; } head value next value next value next 404 101 505 NULL temp

Node Access node * temp = head; While (temp != NULL) { cout << temp->value; // access data fields temp = temp->next; } //finished accessing the node head value next value next value next 404 101 505 NULL temp

Linked List Functions Insert a node Search a node Remove a node Unordered Ordered Search a node Remove a node Sort a list Not covered in C201