Coder Social home page Coder Social logo

cop2805cmod4gpa-old's Introduction

cop2805cMod4GPA

A queue is an abstract data type similar to the stack we discuss in the lecture slides, but it is a FIFO (first-in, first-out) structure as compared to the stack, which is LIFO (last-in, first-out). Think of it as waiting in line for a movie ticket (the British word for line is "queue"). As the line grows, the first person in the line is "removed" to buy a ticket, while the end of the line continues to grow. So the first person in line is the first person to leave, the second in line is second to leave, and so on.

Modify the GenericStack class provided in this modules's lecture source code (GenericStack.java) to implement a generic queue. You may use the original source file and just make necessary changes (including the class names). The push and pop methods will need to be changed to enque (adds an element to the end of the queue) and deque (removes an element from the front of the queue). You can retain the getSize, peek, isEmpty, and toString methods from the GenericStack class; some of them will need to be tweaked, some can be used as is.

Change the "TestGenericStack" class in that file to  "TestGenericQueue" ; here is the main method to use in your TestGenericQueue class which will test your GenericQueue class:

    public static void main(String[] args)
    {
        GenericQueue queue1 = new GenericQueue<>();
        queue1.enque("London");
        queue1.enque("Paris");
        queue1.enque("Berlin");
        log(queue1);
        log(queue1.deque());
        log(queue1.deque());
        log(queue1.deque());
                GenericQueue queue2 = new GenericQueue<>();
        queue2.enque(1);
        queue2.enque(2);
        queue2.enque(3);
        log(queue2);
        log(queue2.deque());
        log(queue2.deque());
        log(queue2.deque());           }

Expected Output -- note that elements are removed in the same order as they are inserted (FIFO), compared to the TestGenericStack program output which removes them in reverse order (LIFO):

queue: [London, Paris, Berlin]
London
Paris
Berlin
queue: [1, 2, 3]
1
2
3

cop2805cmod4gpa-old's People

Contributors

profsingletary avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.