CSS 342 Data Structures, Algorithms, and Discrete Mathematics I

Slides:



Advertisements
Similar presentations
DATA STRUCTURES USING C++ Chapter 5
Advertisements

Lecture 6 Sept 11, 2008 Goals for the day: Linked list and project # 1 list class in STL (section 3.3) stack – implementation and applications.
Data Structure Lecture-5
David Notkin Autumn 2009 CSE303 Lecture 13 This space for rent.
Lecture # 21 Chapter 6 Uptill 6.4. Type System A type system is a collection of rules for assigning type expressions to the various parts of the program.
LINKED QUEUES P LINKED QUEUE OBJECT Introduction Introduction again, the problem with the previous example of queues is that we are working.
Class template Describing a generic class Instantiating classes that are type-specific version of this generic class Also are called parameterized types.
Lecture 6 Feb 12 Goals: stacks Implementation of stack applications Postfix expression evaluation Convert infix to postfix.
Abstract Data Type Example l One more example of ADT: l integer linked list using class l A class with dynamic objects: l Copy constructor l Destructor.
Queues CS-240 & CS-341 Dick Steflik. Queues First In, First Out operation - FIFO As items are added they are chronologically ordered, items are removed.
Queues CS-240 & CS-341 Dick Steflik. Queues First In, First Out operation - FIFO As items are added they are chronologically ordered, items are removed.
Circular List Next field in the last node contains a pointer back to the first node rather than null pointer From any point in such a list it is possible.
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.
CSS 342 DATA STRUCTURES, ALGORITHMS, AND DISCRETE MATHEMATICS I LECTURE CARRANO CHAPT. 9.
CSS 332 PROGRAMMING ISSUES WITH OBJECT-ORIENTED LANGUAGES LECTURE
CSS 342 DATA STRUCTURES, ALGORITHMS, AND DISCRETE MATHEMATICS I LECTURE CARRANO CARRANO CH ; CUSACK CH 8: OPTIONAL.
1 CSC 222: Computer Programming II Spring 2004 Pointers and linked lists  human chain analogy  linked lists: adding/deleting/traversing nodes  Node.
Computer Science Department Data Structure & Algorithms Lecture 8 Recursion.
CSS 342 DATA STRUCTURES, ALGORITHMS, AND DISCRETE MATHEMATICS I LECTURE CARRANO CHAPT 12.
CS 11 C++ track: lecture 5 Today: Member initialization lists Linked lists friend functions.
CSS 342 DATA STRUCTURES, ALGORITHMS, AND DISCRETE MATHEMATICS I LECTURE CUSACK CHAPT 4.
1 Chapter 16 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion and.
CSS 342 DATA STRUCTURES, ALGORITHMS, AND DISCRETE MATHEMATICS I LECTURE CARRANO CH 2, APPENDIX E.
CSS 332 PROGRAMMING ISSUES WITH OBJECT-ORIENTED LANGUAGES LECTURE
CHAPTER 17 LINKED LISTS. In this chapter, you will:  Learn about linked lists  Become aware of the basic properties of linked lists  Explore the insertion.
Lecture 20 Stacks and Queues. Stacks, Queues and Priority Queues Stacks – first-in-last-out structure – used for function evaluation (run-time stack)
LINKED LISTS Midwestern State University CMPS 1053 Dr. Ranette Halverson 1.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department.
Array-Based Implementations Chapter 3 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
CSS 342 DATA STRUCTURES, ALGORITHMS, AND DISCRETE MATHEMATICS I LECTURE CHAPTER 13, 14.
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.
CSS 342 DATA STRUCTURES, ALGORITHMS, AND DISCRETE MATHEMATICS I LECTURE CARRANO CHAPTER 11.
CSS 342 DATA STRUCTURES, ALGORITHMS, AND DISCRETE MATHEMATICS I LECTURE CARRANO C++ INTERLUDE 2, CHAPT 4, 6.
 Review building a complete linked list  List traversal in main ( )  List traversal using a function.
Link Based Implementations
Yan Shi CS/SE 2630 Lecture Notes
CSS 342 Data Structures, Algorithms, and Discrete Mathematics I
CC 215 Data Structures Stack ADT
Doubly Linked List Review - We are writing this code
CSS 342 Data Structures, Algorithms, and Discrete Mathematics I
CSE 143 Linked Lists [Chapter , 8.8] 3/30/98.
Stack and Queue APURBO DATTA.
Linked lists Motivation: we can make arrays, but their functionality is slightly limited and can be difficult to work with Biggest issue: size management.
Chapter 4 Linked Lists
CSS 342 Data Structures, Algorithms, and Discrete Mathematics I
CSS 342 Data Structures, Algorithms, and Discrete Mathematics I
Recursion.
Chapter 16-2 Linked Structures
Abstract Data Types Iterators Vector ADT Sections 3.1, 3.2, 3.3, 3.4
CSS 342 Data Structures, Algorithms, and Discrete Mathematics I
Linked Lists.
CSS 342 Data Structures, Algorithms, and Discrete Mathematics I
CSS 342 Data Structures, Algorithms, and Discrete Mathematics I
CSS 342 Data Structures, Algorithms, and Discrete Mathematics I
Object Oriented Programming COP3330 / CGS5409
CSS 342 Data Structures, Algorithms, and Discrete Mathematics I
CSS 342 Data Structures, Algorithms, and Discrete Mathematics I
Tree A tree is a data structure in which each node is comprised of some data as well as node pointers to child nodes
Cs212: Data Structures Computer Science Department Lab 7: Stacks.
CSS 342 Data Structures, Algorithms, and Discrete Mathematics I
List Implementations Chapter 9
Stacks as Linked lists top_node typedef Stack_entry Node_entry;
[Chapter 4; Chapter 6, pp ] CSC 143 Linked Lists [Chapter 4; Chapter 6, pp ]
Indirection.
Chapter 4 Linked Lists.
Chapter 16 Linked Structures
Array-Based Implementations
Stacks CS-240 Dick Steflik.
CS148 Introduction to Programming II
Chapter 3 Lists, Stacks, and Queues
Presentation transcript:

CSS 342 Data Structures, Algorithms, and Discrete Mathematics I Lecture 9. 150204. CARRANO Chapt. 7, 8

Agenda Finish Stack implementation Linked Lists Quiz turn-back review HW3 Questions Finish Stack implementation Linked Lists Quiz turn-back review

A linked list with head pointer FIGURE 4-3 A head pointer to the first of several linked nodes Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

Let’s build an Int Stack Use a linked list as a data structure Use the following “node” structure struct Node { int value; Node *next; }; Implement Push/Pop Overload the following operators: << Assign = and Copy Constructor +, +=

Push/Pop impl. bool IntStack::Push(int val) { Node *insNode; insNode = new Node; insNode->value = val; insNode->next = head; head = insNode; return true; } bool IntStack::Pop(int &val) { if (head == NULL) return false; } else Node *temp; temp = head; val = temp->value; head = head->next; delete temp; return true; IntStack::IntStack() { head = NULL; } IntStack::~IntStack() { this->Clear(); }

Proper stack clean up IntStack::~IntStack() { this->Clear(); } void IntStack::Clear() { int a; while (Pop(a)); }

Let’s build an Int Stack Use a linked list as a data structure Use the following “node” structure struct Node { int value; Node *next; }; Implement Push/Pop Overload the following operators: << Assign = and Copy Constructor +, +=

Print Stack ostream& operator<<(ostream &outStream, const IntStack &stack) { Node *pNode; pNode = stack.head; while (pNode != NULL) outStream << pNode->value << endl; pNode = pNode->next; } return outStream;

Let’s build an Int Stack Use a linked list as a data structure Use the following “node” structure struct Node { int value; Node *next; }; Implement Push/Pop Overload the following operators: << Assign =, copy constructor +

Computer Scientist of the week Anonymous Computer Scientist Hactivists Named 100 most influential people in the world (Time) Generally attack through DDOS Philosophy generally anarchic and swings between entertaining pranks or political activism Strong support Occupy Movement and Arab Spring Controversial methods

Assignment (=) void IntStack::operator=(IntStack &source) { Node *sNode, *dNode, *insNode; if (this == &source) return; this->Clear(); if (source.head == NULL) return; dNode = new Node; dNode->value = (source.head)->value; this->head = dNode; sNode = (source.head)->next; while (sNode != NULL) insNode = new Node; insNode->value = sNode->value; dNode->next = insNode; dNode = dNode->next; sNode = sNode->next; }

Quiz Review http://www.uwb.edu/registration/policies/grading/grading-ug