Preview

Data Structure

Satisfactory Essays
Open Document
Open Document
785 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Data Structure
WXES1115/WXES1117 Data Structures
Lab 10: Queue

1. Write a generic queue class called MyQueue using LinkedList. Implement the following methods: a. public void enqueue(E o) b. public E dequeue() c. public E peek() d. public int getSize() e. public boolean isEmpty(); f. public String toString() public static void main(String[] args) { // TODO code application logic here MyQueue <String > fruitQ = new MyQueue <String >(); fruitQ.enqueue("Apple"); fruitQ.enqueue(" Orange"); fruitQ.enqueue("Grapes"); fruitQ.enqueue("Cherry"); fruitQ.enqueue("pear"); System.out.println(fruitQ);

System.out.println( fruitQ.peek()); fruitQ.dequeue(); System.out.println(fruitQ.isEmpty()); System.out.println(fruitQ.getSize()); }
}
public class MyQueue<E> { private LinkedList<E> list = new LinkedList<E>(); public void enqueue(E o) { list.add(o); } public E dequeue(){
E o = list.get(getSize() - 1); list.remove(getSize() - 1); return o ; } public E peek() { return list.get(getSize() - 1); } public int getSize() { return list.size(); }

public boolean isEmpty() { return list.isEmpty(); }

@Override public String toString() { return "queue: " + list.toString();
}

} public class fruitQ { public static void main(String[] args) { MyQueue <String > t = new MyQueue <String >(); t.enqueue("Apple"); t.enqueue(" Orange"); t.enqueue("Grapes"); t.enqueue("Cherry"); System.out.println(t.toString()); }
}

2. Write a test program that keeps the list of the following fruit items called fruitQ in the queue in the following order: Apple, Orange, Grapes, Cherry. Perform the following operations

You May Also Find These Documents Helpful

  • Powerful Essays

    B. Write Code inside the main method and test it by compiling (F9) and running (Shift + F6) your code.…

    • 2338 Words
    • 10 Pages
    Powerful Essays
  • Powerful Essays

    Mat 540 Week 4 Paper

    • 1775 Words
    • 8 Pages

    * Provide a set of values that will test the normal operation of this program segment. Defend your choices.…

    • 1775 Words
    • 8 Pages
    Powerful Essays
  • Good Essays

    Unit 5 PT1420

    • 959 Words
    • 7 Pages

    2. You need to test a condition and then execute one set of statements if the condition is true. If the condition is false, you need to execute a different set of statements. What structure will you use?…

    • 959 Words
    • 7 Pages
    Good Essays
  • Powerful Essays

    here is for the specter of a quiz to always be hanging over the student where he knows he…

    • 83928 Words
    • 594 Pages
    Powerful Essays
  • Satisfactory Essays

    a.x is available to code that is written outside the Sphere class. b.radius is not available to code written outside the Sphere class. c.radius, x, y, and z are called members of the Sphere class. d.z is available to code that is written outside the Sphere class.…

    • 1368 Words
    • 9 Pages
    Satisfactory Essays
  • Good Essays

    Sheet Java Study Guide

    • 576 Words
    • 3 Pages

    1. Write a program to compute the area and circumference of a rectangle 3 inche wide by 5 inches long.…

    • 576 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    This Is a Paper

    • 469 Words
    • 2 Pages

    Provide a set of values that will test the normal operation of this program segment. Defend your choices.…

    • 469 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Java Programming I Exam

    • 912 Words
    • 4 Pages

    Locating and repairing all syntax errors is part of the process of ____ a program.…

    • 912 Words
    • 4 Pages
    Satisfactory Essays
  • Good Essays

    Array Structure Proposal

    • 574 Words
    • 3 Pages

    Write a 2- to 3-page proposal describing the purpose of that structure and write the pseudocode for that structure.…

    • 574 Words
    • 3 Pages
    Good Essays
  • Better Essays

    Database Design

    • 1196 Words
    • 5 Pages

    “A database is a structured collection of records or data that is stored in a computer system. In order for a database to be truly functional, it must not only store large amounts of record, but also be able to access those records fast and efficiently. In addition, new information and changes should also be easy to input.” (tech-faq.com) To be useful over a long term the database should be able to store all the records necessary for the business to function as well as be able to get all of this information back in case of a system failure or a crash. If all the information is loss a business could go bankrupt so the database is a fail safe for all the information the company has.…

    • 1196 Words
    • 5 Pages
    Better Essays
  • Satisfactory Essays

    |Identify the legislation that relates to the recording, storage and sharing of information in health and social care |4222.209.1.1 |…

    • 468 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    Cen 254 Data Structure

    • 924 Words
    • 4 Pages

    T. You are only allowed to use the methods of the Tree and Binary Tree ADTs…

    • 924 Words
    • 4 Pages
    Powerful Essays
  • Best Essays

    Historically, a manual file system was composed of a system of file folders and filing cabinets.…

    • 2439 Words
    • 17 Pages
    Best Essays
  • Good Essays

    Graph on Data Structure

    • 2152 Words
    • 9 Pages

    Next important set is E, which is called edge-set. E is a subset of V x V. Simply speaking, each edge connects two vertices, including a case, when a vertex is connected to itself (such an edge is called a loop). All graphs are divided into two big groups: directed and undirected graphs. The difference is that edges in directed graphs, called arcs, have a direction. These kinds of graphs have much in common with each other, but significant differences are also present. We will accentuate which kind of graphs is considered in the particular algorithm description. Edge can be drawn as a line. If a graph is directed, each line has an arrow.…

    • 2152 Words
    • 9 Pages
    Good Essays
  • Satisfactory Essays

    B- Suppose you are going to build a new system that automates or improves the interview process for the career services department of your school. Develop a requirements definition for the new system. Include both functional and non-functional system requirements. Pretend you will release the system in three different versions. Prioritize the requirements accordingly.…

    • 829 Words
    • 4 Pages
    Satisfactory Essays

Related Topics