CSE 143 Section AD - PowerPoint PPT Presentation

About This Presentation
Title:

CSE 143 Section AD

Description:

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 ... – PowerPoint PPT presentation

Number of Views:43
Avg rating:3.0/5.0
Slides: 13
Provided by: JeffW162
Category:
Tags: cse | queues | section | stacks

less

Transcript and Presenter's Notes

Title: CSE 143 Section AD


1
CSE 143 Section AD
  • Quiz Section 15

2
Announcements
  • First part of HW 5 due today, youll 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

3
Agenda
  • Linked List Examples from Last Time
  • Stacks
  • Queues
  • Event Handling

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.

5
Queues
  • Queues follow a FIFO (First-In-First-Out) pattern

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

7
FlightQueueFlightQueue()
  • FlightQueueFlightQueue()
  • front NULL
  • back NULL

8
FlightQueueFlightQueue()
  • FlightQueueFlightQueue()
  • Node cur front, temp
  • while(cur ! NULL)
  • temp cur
  • cur cur-gtnext
  • delete temp

9
Copy Constructor
  • FlightQueueFlightQueue(FlightQueue other)
  • front back NULL
  • Node curOfOther other.front
  • while(curOfOther ! NULL)
  • insert(curOfOther)
  • curOfOther curOfOther -gt next

10
insert
  • void FlightQueueinsert(const Flight newFlight)
  • Node addMe new Node
  • addMe -gt myFlight newFlight
  • addMe -gt next NULL
  • if(front NULL)
  • front back addMe
  • else
  • back -gt next addMe
  • back addMe

11
remove
  • Flight FlightQueueremove()
  • if(back front)
  • back NULL
  • Flight returnMe front -gt myFlight
  • Node newFront front -gt next
  • delete front
  • front newFront
  • return returnMe

12
getFront
  • Flight FlightQueuegetFront()
  • return front -gt myFlight
Write a Comment
User Comments (0)
About PowerShow.com