Presentation is loading. Please wait.

Presentation is loading. Please wait.

Jeff West - Quiz Section 15

Similar presentations


Presentation on theme: "Jeff West - Quiz Section 15"— Presentation transcript:

1 Jeff West - Quiz Section 15
CSE 143 Section AD Quiz Section 15 8/7/2001 Jeff West - Quiz Section 15

2 Jeff West - Quiz Section 15
Announcements First part of HW 5 due today, you’ll get it back Thursday… Quiz Thursday – Stacks & Queues Homework 5 Demo sign-up sheet going around… Final Review Sessions next Wednesday and Thursday nights – time & location TBA 10 more days until our summer vacation… Tha Usual… 8/7/2001 Jeff West - Quiz Section 15

3 Jeff West - Quiz Section 15
Agenda Linked List Examples from Last Time Stacks Queues Event Handling 8/7/2001 Jeff West - Quiz Section 15

4 Jeff West - Quiz Section 15
Stacks Stacks follow a FILO (First-In-Last-Out) pattern… Their behind-the-scenes implementation can be handled using arrays, linked lists, vectors, etc. 8/7/2001 Jeff West - Quiz Section 15

5 Jeff West - Quiz Section 15
Queues Queues follow a FIFO (First-In-First-Out) pattern… 8/7/2001 Jeff West - Quiz Section 15

6 Jeff West - Quiz Section 15
Queue.h (Linked List) struct Node { Flight myFlight; Node* next; } Class FlightQueue { public: FlightQueue(); ~FlightQueue(); FlightQueue(FlightQueue&); void insert(const Flight&); // add element to rear of queue Flight remove(); // remove element from front of queue Flight getFront(); // return a copy of element at the front of queue private: Node* front; Node* back; 8/7/2001 Jeff West - Quiz Section 15

7 FlightQueue::FlightQueue();
front = NULL; back = NULL; } 8/7/2001 Jeff West - Quiz Section 15

8 FlightQueue::~FlightQueue()
Node* cur = front, *temp; while(cur != NULL) { temp = cur; cur = cur->next; delete temp; } 8/7/2001 Jeff West - Quiz Section 15

9 Jeff West - Quiz Section 15
Copy Constructor FlightQueue::FlightQueue(FlightQueue& other) { front = back = NULL; Node* curOfOther = other.front; while(curOfOther != NULL) { insert(curOfOther); curOfOther = curOfOther -> next; } 8/7/2001 Jeff West - Quiz Section 15

10 Jeff West - Quiz Section 15
insert void FlightQueue::insert(const Flight& newFlight) { Node* addMe = new Node; addMe -> myFlight = newFlight; addMe -> next = NULL; if(front == NULL) front = back = addMe; else { back -> next = addMe; back = addMe; } 8/7/2001 Jeff West - Quiz Section 15

11 Jeff West - Quiz Section 15
remove Flight FlightQueue::remove() { if(back == front) back = NULL; Flight returnMe = front -> myFlight; Node* newFront = front -> next; delete front; front = newFront; return returnMe; } 8/7/2001 Jeff West - Quiz Section 15

12 Jeff West - Quiz Section 15
getFront Flight FlightQueue::getFront() { return front -> myFlight; } 8/7/2001 Jeff West - Quiz Section 15


Download ppt "Jeff West - Quiz Section 15"

Similar presentations


Ads by Google