Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science 2 Queue Day 2.

Similar presentations


Presentation on theme: "Computer Science 2 Queue Day 2."— Presentation transcript:

1 Computer Science 2 Queue Day 2

2 Learning Objectives Improve reading a program that uses linked lists.
Be able to model a line using a linked list.

3 begin top:=nil; a(top); d(top); c(top, 14); c(top, 7); c(top, 35);
procedure c(var top:ptrtype; val:integer); var front, back:ptrtype; begin back:= top; front:= top^.next; while (front <> nil) and (front^.num<> val) do back:= front; front:= front^.next; end; if (front = nil) then writeln('Sorry') else writeln(front^.num); back^.next:= front^.next; dispose(front); procedure d(top:ptrtype); if top<>nil then writeln(top^.num); d(top^.next); program dryrun51507; type ptrtype=^rectype; rectype=record num:integer; next:ptrtype; end; var top:ptrtype; procedure a(var top:ptrtype); temp:ptrtype; count:integer; begin for count:= 1 to 4 do new(temp); temp^.num:=count*7; temp^.next:=top; top:=temp; begin top:=nil; a(top); d(top); c(top, 14); c(top, 7); c(top, 35); end.

4 Program options: Write a program that will model a line in a bank. Using a menu and a while loop. Add person to the line. Get their name and put them in the line. Show all of the people in the line. Serve a person. Say the name of the person being served. Close the bank. (When this is chosen, everyone left in the line is dismissed personally. Ex. Sorry we are closed, please come back tomorrow, John, Jan , Jane, Jal) Push: Time how long each person waits in the line. Add a provision for a person cutting in line. Create a screen saver that uses a queue help modeling the motion. Have the lines around the screen saver where the lines are added to one end of the series and the line in the back of the series is removed. Note: You need to incorporate the pointers into this option.


Download ppt "Computer Science 2 Queue Day 2."

Similar presentations


Ads by Google