Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Array Based Stacks and Queues2-15-2012Opening DiscussionDo you have any questions about the assignment?Minute essaysPrivate messages.Psychological impact of ubiquitous networking.One ServerSocket per port. Lots of Sockets going through it.3-D graphics.GUIs and networking, networked games.While loop in chatroom. Could you use for?Abstract Data Types (ADTs)Today we will be working with the simplest forms of abstract data types. These are things that hold data and specify how you can interact with it and what happens when data is added or removed.In Scala an ADT is basically a completely abstract trait for a container with comments giving details on what happens with each method.Note that it doesn't specify how things happen. That is why it would be an interface. ADTs can be implemented in many different ways.Stacks and QueuesThe simplest forms of ADTs, they each require one method to add an element and one method to remove an element. For easy of use we typically also include two other methods.Methods of a stackpush, pop, peek, isEmptyMethods of a queueenqueue, dequeue, peek, isEmptyThe Difference?Push and enqueue add items while pop and dequeue remove items. The difference is what item gets removed.A stack is last in, first out (LIFO). Just think of how you interact with a stack.A queue is first in, first out (FIFO). If you were British you would use the term queue instead of line for what you stand in when waiting for something.Array Based StackLet's write a trait called MyStack with the methods we said should be in it. Make the interface generic so it can handle any type.Now let's write a class called ArrayStack and make it extend MyStack. Fill in the code for ArrayStack and add testing.Array Based QueueNow we will do the same thing for a queue. Make a MyQueue trait and an ArrayQueue class.Other CodeOne of the most standard applications of a stack is a reverse polish calculator (RPC).Let's make a class for a RPC then make a command that will use it.Queue of commands for networking.Minute EssayQuestions?You will be turning in your project as an assignment on
View Full Document