1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
svet-max [94.6K]
4 years ago
8

Write a method for the Queue class in the queue.java program (Listing 4.4) that displays the contents of the queue. Note that th

is does not mean simply displaying the contents of the underlying array. You should show the queue contents from the first item inserted to the last, without indicating to the viewer whether the sequence is broken by wrapping around the end of the array. Be careful that one item and no items display properly, no matter where front and rear are.
Listing 4.4 is below

class Queue

{

private int maxSize;

private long[] queArray;

private int front;

private int rear;

private int nItems;

//

public Queue(int s)

{

maxSize = s;

queArray = new long[maxSize];

front =0;

rear = -1;

nItems = 0;

}

//

public void insert(long j)

{

if(rear == maxSize -1)

rear = -1;

queArray[++rear] = j;

nItems++;

}

//

public long remove()

{

long temp = queArray[front++];

if(front == maxSize)

front = 0;

nItems--;

return temp;

}

//

public long peekFront()

{

return queArray[front];

}

//

public boolean isEmpty()

{

return(nItems==0);

}

//

public boolean isFull()

{

return (nItems==maxSize);

}

//

public int size()

{

return nItems;

}

//

} //end class

class QueueApp

{

public static void main(String[] args)

{

Queue theQueue = new Queue(5);

theQueue.insert(10);

theQueue.insert(20);

theQueue.insert(30);

theQueue.insert(40);

theQueue.remove();

theQueue.remove();

theQueue.remove();

theQueue.insert(50);

theQueue.insert(60);

theQueue.insert(70);

theQueue.insert(80);

while( !theQueue.isEmpty() )

{

long n = theQueue.remove();

System.out.print(n);

System.out.print( " ");

}

System.out.println(" ");

} //end main()

} //end class

4.2

Create a Deque class based on the discussion of deques (double-ended queues) in this chapter. It should include insertLeft(), insertRight(), removeLeft(), removeRight(), isEmpty(), and isFull() methods. It will need to support wraparound at the end of the array, as queues do.

4.3

Write a program that implements a stack class that is based on the Deque class in the Programming Project 4.2. This stack class should have the same methods and capabillities as the StackX class in the stack.java program (Listing 4.1).

Listing 4.1 is below

class StackX

{

private int maxSize;

private long[] stackArray;

private int top;

//

public stackX(int s)

{

maxSize = s;

stackArray = new long[maxSize];

top = -1;

}

//

public void push(long j)

{

stackArray[++top] = j;

}

//

public long pop()

{

return stackArray[top --];

}

//

public long peek()

{

return stackArray[top];

}

//

public boolean isEmpty()

{

return (top == -1);

}

//

public boolean isFull()

{

return (top == maxSize-1);

}

//

} //end class StackX

class StackApp

{

public static void main(String[] args)

{

StackX the Stack = new StackX(10);

theStack.push(20);

theStack.push(40);

theStack.push(60);

theStack.push(80);

while( !theStack.isEmpty() )

{

long value = theStack.pop();

System.out.print(value);

System.out.print(" ");

} //end while

System.out.println(" ");

} //end main

} //end class
Computers and Technology
1 answer:
pentagon [3]4 years ago
6 0

Answer:

yeet yeet my pee pee fell off

Explanation:

You might be interested in
Where is the start frame delimiter found in the Ethernet frame
Ksju [112]
Answer: The SFD is the eight-bit (one-byte) value that marks the end of the preamble, which is the first field of an Ethernet packet, and indicates the beginning of the Ethernet frame.
8 0
3 years ago
In the following nested loop structure, which loop does the program EXIT first?
seropon [69]

Answer:

The loops are nested, and the program ends when loop 1 is completed. Since loop 4 is the innermost one, that one is completed first.

7 0
3 years ago
Which command can be used to connect to a remote windows share called data on the server called fileserver?
DiKsa [7]

c. c.) smbclient //fileserver/data

7 0
3 years ago
As time goes on, technology is likely to _______. A. Increase in complexity b. Decrease in complexity c. Stay at the same comple
amid [387]

Answer:

The answer to this question is the option "A".

Explanation:

In this question, the answer is Increase in complexity because, In computer science, the computerized or simply complexity is an algorithm. In this algorithm, the number of the resource is required for moving it (a quality separate to “complexity” in a conventional reason). So in this question the answer is option A that is  Increase in complexity.

5 0
3 years ago
Jason attempts to hack into a banking site to steal customer information. He finds the security of the Web site lacking and is a
r-ruslan [8.4K]

Answer:

honey pot

Explanation:

Jason attempts to hack into a banking site to steal customer information. He finds the security of the Web site lacking and is able to access the site with ease. Jason is arrested the next day and charged with computer crime. The banking site was able to track​ Jason's IP address because he had unknowingly attacked a honey pot.

8 0
3 years ago
Other questions:
  • Which sector provides scope for multimedia designers?
    10·1 answer
  • A document repository is down when you attempt to access it. which isa principle is being violated?
    13·1 answer
  • Isp servers are continually connected to a larger network, called a regional network, which, in turn, is connected to one of the
    6·1 answer
  • An organizational structure that combines a functional structure with a divisional structure to emphasize project or program nee
    8·1 answer
  • In an ethernet network, the signal that is sent to indicate a signal collision is called a ________ signal.
    7·1 answer
  • Which of the following choices best completes the above flowchart?
    11·1 answer
  • What is the world first mobile phone brand​
    5·2 answers
  • How did Avery and Garth most likely create their
    13·1 answer
  • I need help converting this to python but i have no idea how to.
    12·1 answer
  • if a manager identifies numerous data integrity issues, she/he should consider the reports generated from that data as invalid a
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!