Lecture15_16 - Lecture 15 - Linked Lists ECE 3090 Software...

Info iconThis preview shows pages 1–14. Sign up to view the full content.

View Full Document Right Arrow Icon
ECE 3090 Software for Engineering Systems Dr. Ayanna Howard School of Electrical and Computer Engineering Georgia Institute of Technology Lecture 15 - Linked Lists
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Adapted from “Brief Version of Starting Out with C++” What if?? Wanted to create a database of students for ECE3090? Wanted to collect game statistics associated with teams until the Final Four? Want to document your collection of Pokeman cards?
Background image of page 2
3 Adapted from “Brief Version of Starting Out with C++” Introduction to the Linked List ADT Linked list : set of data structures (nodes ) that contain references to other data structures NULL list head
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Adapted from “Brief Version of Starting Out with C++” Introduction to the Linked List ADT References may be addresses or array indices Data structures can be added to or removed from the linked list during execution NULL list head newNode
Background image of page 4
5 Adapted from “Brief Version of Starting Out with C++” Linked Lists vs. Arrays and Vectors Linked lists can grow and shrink as needed, unlike arrays, which have a fixed size Linked lists can insert a node between other nodes easily NULL list head
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Adapted from “Brief Version of Starting Out with C++” Node Organization A node contains: data: one or more data fields – may be organized as structure, object, etc. a pointer that can point to another node data pointer
Background image of page 6
7 Adapted from “Brief Version of Starting Out with C++” Linked List Organization Linked list contains 0 or more nodes: Has a list head to point to first node Last node points to NULL NULL list head
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 Adapted from “Brief Version of Starting Out with C++” Empty List If a list currently contains 0 nodes, it is the empty list In this case the list head points to NULL NULL list head
Background image of page 8
9 Adapted from “Brief Version of Starting Out with C++” Declaring a Node Declare a node: struct ListNode { int data; ListNode *next; }; No memory is allocated at this time
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 Adapted from “Brief Version of Starting Out with C++” Defining a Linked List Define a pointer for the head of the list: ListNode *head = NULL; Head pointer initialized to NULL to indicate an empty list NULL head
Background image of page 10
11 Adapted from “Brief Version of Starting Out with C++” NULL Pointer Is used to indicate end-of-list Should always be tested for before using a pointer: ListNode *p; while (p != NULL) . .. Can also test the pointer itself: while (!p) . .. // same meaning // as above
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
12 Adapted from “Brief Version of Starting Out with C++” Linked List Operations Basic operations: append a node to the end of the list insert a node within the list traverse the linked list delete a node delete/destroy the list
Background image of page 12
13 Adapted from “Brief Version of Starting Out with C++” Contents of NumberList.h 1 // Specification file for the NumberList class 2 #ifndef NUMBERLIST_H 3 #define NUMBERLIST_H 4 5 class NumberList 6 { 7 private: 8 // Declare a structure for the list
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 14
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/09/2009 for the course ECE 3090 taught by Professor Staff during the Fall '08 term at Georgia Institute of Technology.

Page1 / 94

Lecture15_16 - Lecture 15 - Linked Lists ECE 3090 Software...

This preview shows document pages 1 - 14. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online