120 likes | 283 Views
CSE 143 Section AD. 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
E N D
CSE 143 Section AD Quiz Section 15 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… Jeff West - Quiz Section 15
Agenda • Linked List Examples from Last Time • Stacks • Queues • Event Handling 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. Jeff West - Quiz Section 15
Queues • Queues follow a FIFO (First-In-First-Out) pattern… 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; } Jeff West - Quiz Section 15
FlightQueue::FlightQueue(); FlightQueue::FlightQueue() { front = NULL; back = NULL; } Jeff West - Quiz Section 15
FlightQueue::~FlightQueue() FlightQueue::~FlightQueue() { Node* cur = front, *temp; while(cur != NULL) { temp = cur; cur = cur->next; delete temp; } } 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; } } 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; } } 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; } Jeff West - Quiz Section 15
getFront Flight FlightQueue::getFront() { return front -> myFlight; } Jeff West - Quiz Section 15