1 / 12

CSE 143 Section AD

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

casey-guy
Download Presentation

CSE 143 Section AD

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSE 143 Section AD Quiz Section 15 Jeff West - Quiz Section 15

  2. 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

  3. Agenda • Linked List Examples from Last Time • Stacks • Queues • Event Handling Jeff West - Quiz Section 15

  4. 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

  5. Queues • Queues follow a FIFO (First-In-First-Out) pattern… Jeff West - Quiz Section 15

  6. 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

  7. FlightQueue::FlightQueue(); FlightQueue::FlightQueue() { front = NULL; back = NULL; } Jeff West - Quiz Section 15

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

  9. 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

  10. 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

  11. 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

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

More Related