 Review building a complete linked list  List traversal in main ( )  List traversal using a function.

Slides:



Advertisements
Similar presentations
Dynamic Allocation and Linked Lists. Dynamic memory allocation in C C uses the functions malloc() and free() to implement dynamic allocation. malloc is.
Advertisements

Stacks, Queues, and Linked Lists
Data Structures Linked Lists Linked List Basics. Array Disadvantages Arrays, although easy to understand have lots of disadvantages Contiguous Memory.
Singly Linked List BTECH, EE KAZIRANGA UNIVERSITY.
Doubly linked list concept Node structure Insertion sort Insertion sort program with a doubly linked list.
1 Pointers and Strings Section 5.4, , Lecture 12.
Data Structure Lecture-5
Functions Prototypes, parameter passing, return values, activation frams.
Templated Functions. Overloading vs Templating  Overloaded functions allow multiple functions with the same name.
PASSING PARAMETERS 1. 2 Parameter Passing (by Value) Parameters Formal Parameters – parameters listed in the header of the function Variables used within.
Circular Linked List. COMP104 Circular Linked List / Slide 2 Circular Linked Lists * A Circular Linked List is a special type of Linked List * It supports.
CCSB364 Data Structures & Algorithms Pointer & Linked List.
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
Pointers Example Use int main() { int *x; int y; int z; y = 10; x = &y; y = 11; *x = 12; z = 15; x = &z; *x = 5; z = 8; printf(“%d %d %d\n”, *x, y, z);
Programming Pointers. COMP104 Lecture 32 / Slide 2 Pointers l Pointers are objects whose values are the locations of other objects l Pointers are memory.
Dynamic Allocation and Linked Lists. Dynamic memory allocation in C C uses the functions malloc() and free() to implement dynamic allocation. malloc is.
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.
 Review structures  Program to demonstrate a structure containing a pointer.
March 6, 2014CS410 – Software Engineering Lecture #10: C++ Basics IV 1 Structure Pointer Operator For accessing members in structures and classes we have.
CS 11 C++ track: lecture 5 Today: Member initialization lists Linked lists friend functions.
+ struct Node { + int x; + Node * next; + }; + Node *mylist; + Node *mylist = NULL; head 121.
Tracing through E01, question 9 – step 1 // p02.cc P. Conrad, for CISC181 07S // Exam question for E01 #include using namespace std; void mysteryFunction(int.
Lecture 6 Feb 8, 2012 Goals: Linked list (Chapter 3) list class in STL (section 3.3) implementing with linked lists.
Algorithms and Data Structures
Computer Programming for Engineering Applications ECE 175 Intro to Programming.
LINKED LISTS Midwestern State University CMPS 1053 Dr. Ranette Halverson 1.
 Head pointer  Last node  Build a complete linked list  Node deletion  Node insertion  Helpful hints.
Trees. What is a tree? You know…  tall  green  leafy  possibly fruit  branches  roots  I’m sure you’ve seen them.
Pointer. lvalues In C++, any expression that refers to an internal memory location is called an lvalue Appear on left side of assignment statement e.g.
Revision on C++ Pointers TCP1201: 2013/2014. Pointer Basics  Why pointer is important? 1. Reference/Point to existing data without cloning the data.
Circular Linked List Singly Circular Linked List Doubly Circular Linked List.
 Memory setup  Pointer declaration  Address operator  Indirection  Printing addresses or pointers.
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.
 Memory from the heap  Dynamic memory allocation using the new operator  Build a dynamic linked list  Another way of traversing a linked list 
Linked List. Insert a node at the beginning #include struct node { int data; struct node* next; }; struct node* head; void Insert(int x) { node *temp.
Lesson xx Why use functions Program that needs a function Function header Function body Program rewritten using a function.
  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.
CISC220 Spring 2010 James Atlas Lecture 04: Pointers, Functions, Memory Management, ADTs, Classes, Hardware, Software, Graphics, Networking, AI, Databases,
Programming Circular Linked List.
Popping Items Off a Stack Using a Function Lesson xx
Pointers & Arrays.
Sequences 6/18/2018 8:51 PM C201: Linked List.
Doubly Linked List Review - We are writing this code
Linked list.
Traversing a Linked List
Linked lists.
Pointers Psst… over there.
Sequences 9/18/ :20 PM C201: Linked List.
Stack Lesson xx   This module shows you the basic elements of a type of linked list called a stack.
Pointers Psst… over there.
Recursion.
Chapter 16-2 Linked Structures
Linked List Lesson xx   In this presentation, we introduce you to the basic elements of a linked list.
Popping Items Off a Stack Lesson xx
Stack and Queues Stack implementation using Array
Introduction to Programming
Pointers & Functions.
Queues FIFO Enqueue Dequeue Peek.
Dynamic Memory A whole heap of fun….
Pointers Lecture 1 Thu, Jan 15, 2004.
Stacks LIFO C C B B B B A A A A A Push (A) Push (B) Push (C) Pop Pop.
CS148 Introduction to Programming II
Pointers & Arrays.
List Iterator Implementation
Pointers & Functions.
The Stack.
Linked lists.
Pointers, Dynamic Data, and Reference Types
Linked Lists.
Presentation transcript:

 Review building a complete linked list  List traversal in main ( )  List traversal using a function

struct entry { int value; entry* next; }; int main() { entry n1, n2, n3; entry* head = &n1; n1.next = &n2; n2.next = &n3; n3.next = 0; n1.value = 100; n2.value = 200; n3.value = 300; entry * temp; temp= head; // traverse the list while (temp != NULL) { cout value next << endl; temp = temp->next; } return 0; }

entry n1, n2, n3; entry* head = &n1; n1.next = &n2; n2.next = &n3; n3.next = 0; n1.value = 100; n2.value = 200; n3.value = 300; n1 n1.valuen1.next n2 n2.valuen2.next n3 n3.valuen3.next (56c) (7fa)(88b) 7fa 88b 0 56c head

n1 n1.valuen1.next n2 n2.valuen2.next n3 n3.valuen3.next (56c) (7fa)(88b) 7fa 88b 0 56c head 56c temp entry * temp; temp= head;

n1 n1.valuen1.next n2 n2.valuen2.next n3 n3.valuen3.next (56c) (7fa)(88b) 7fa 88b 0 56c head 56c temp while (temp != NULL) { cout value next << endl; temp = temp->next; }

n1 n1.valuen1.next n2 n2.valuen2.next n3 n3.valuen3.next (56c) (7fa)(88b) 7fa 88b 0 56c head 56c temp 56c 100 7fa temp temp->value temp->next

temp = temp->next; n1 n1.valuen1.next n2 n2.valuen2.next n3 n3.valuen3.next (56c) (7fa)(88b) 7fa 88b 0 56c head 7fa temp

while (temp != NULL) { cout value next << endl; temp = temp->next; } n1 n1.valuen1.next n2 n2.valuen2.next n3 n3.valuen3.next (56c) (7fa)(88b) 7fa 88b 0 56c head 7fa temp

56c 100 7fa 7fa b 88b n1 n1.valuen1.next n2 n2.valuen2.next n3 n3.valuen3.next (56c) (7fa)(88b) 7fa 88b 0 56c head 0 temp

struct entry { int value; entry* next; }; void printList(const entry*); // prototype int main() { entry n1, n2, n3; n1.next = &n2; n2.next = &n3; n3.next = 0; entry* head = &n1; printList(head); return 0; } void printList(const entry* pointer) { while (pointer != 0 ) { cout value next << endl; pointer = pointer->next; } }

struct entry { int value; entry* next; }; void printList(const entry*); // prototype int main() { entry n1, n2, n3; n1.next = &n2; n2.next = &n3; n3.next = 0; entry* head = &n1; printList(head); return 0; } void printList(const entry* pointer) { while (pointer != 0 ) { cout value next << endl; pointer = pointer->next; } } 1 2 3

n1 n1.valuen1.next n2 n2.valuen2.next n3 n3.valuen3.next (56c) (7fa)(88b) 7fa 88b 0 56c head 56c pointer void printList(const entry* pointer) { while (pointer != 0 ) { cout value next << endl; pointer = pointer->next; } }

Building a complete linked list List traversal in main ( ) List traversal using a function