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
What happens when the computer is thrashing? quizzlet?
lutik1710 [3]
When computers need to use more memory than have RAM, they'll swap out pages of memory to their drive. When they need those memory pages, they'll swap out others and swap in the needed ones. If a computer needs enough additionall memory, it can get so busy swapping that it doesn't have any (or very little) time to do any useful work. That is called thrashing.

Unix calls swapping swapping. Windows calls it paging, probably because of the memory pages. Memory pages are 4096 (4KB) sections of memory.

Unix drives are usually partitioned with a swap partition, and swap files can be made in the filesystem. Windows just has pagefiles[s].
5 0
4 years ago
Any software or program that comes in many forms and is designed to disrupt the normal operation of a computer by allowing an un
Paha777 [63]
<span>Any software or program that comes in many forms and is designed to disrupt the normal operation of a computer by allowing an unauthorized process to occur or by granting unauthorized access is known as: Malicious code
Malicious code is often created to steal some information from another user without they realizing it, such as address, credit card number, social security number, email password, etc.</span>
4 0
4 years ago
How fast can the winds blow in a tornado?
sp2606 [1]
Over 200 mph generally now I says 300 mph
6 0
4 years ago
Read 2 more answers
Super easy question but you have to think about it because it’s not that easy I’ll mark brainliest for first answer Explain the
kkurt [141]

Answer:

Databases are not that simple. Now we not only have a Data warehouse, but we also have the Data Lake as well. We also have NoSQL and SQL form of support with these modern databases. The JSON format is rocking. You can hence through JSON store the text, image, audio, video, etc in one go. And like the first five can be a text, the next five can be an image then again a text than video, and so on. And it is super easy to access them as well. Also, you can edit them quite easily as well. It's not that hard like the Lisp used to be in the past. And supermarket has a mix blend of the database. And modern databases like Data Lake can be very useful, undoubtedly.

You can store security type of requirements, like CCTV footage, each shop details like shop ID, Product list, shop type, electricity bill, hours of opening, floor, facilities, no. of employees, etc., and like this, we can have the details for the entire supermarket, and each shop there definitely. And we can perform various actions on behalf of each shop and market as well. The database can hence be very useful definitely

Explanation:

Please check the answer.

8 0
3 years ago
Order the steps to use a logical argument as a rule type.
muminat

Answer:

Click home tab, click conditional formatting, click new rule, use formula to determine

6 0
3 years ago
Read 2 more answers
Other questions:
  • Which of the following is not a network connection LAN WAN SAN MAN
    6·1 answer
  • The gaining of unauthorized access to data in a<br> system or computer:
    11·1 answer
  • A __engineer specializes in computer hardware design and integration.
    15·1 answer
  • Mateo could not find the undo command or shortcut. He should _____.
    15·2 answers
  • __________ offers a mechanism to accomplish four security goals: confidentiality, integrity, authentication, and nonrepudiation.
    9·1 answer
  • Which is true about POP3 and IMAP for incoming email?
    10·1 answer
  • Which of the following are causes of a run-time error. Choose all that apply.
    13·1 answer
  • Do pc players ever go outside?
    11·2 answers
  • Please help it’s timed
    5·1 answer
  • Working with text in presentation programs is very ____ using text in other applications.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!