subject

Write a method for the queue class in the queue. java program (listing 4.4) that displays the contents of the queue. note that this 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 includeand 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

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 19:00
Acompany is hiring professionals for web designing. the firm is small with few resources. they want employees who possess problem-solving skills and can independently carry out responsibilities. which kind of employee should they select?
Answers: 2
question
Computers and Technology, 24.06.2019 07:30
Jason is working on a microsoft excel worksheet and he wants to create a print preview shortcut. his teacher asks him to access the customization option to create the new shortcut. which two tabs should jason select to place the print preview shortcut on the worksheet toolbar? a. new tab (custom) and new group (custom) b. new file tab (custom) and new tab (custom) c. new custom group and new command d. new custom tab and new command
Answers: 2
question
Computers and Technology, 24.06.2019 08:20
Evaluate the scenario below and indicate how to handle the matter appropriately. situation: michael received an e-mail from what he thought was his doctor’s office, requesting his social security number. since he had just been in to see his doctor last week, he replied to the e-mail with his social security number.
Answers: 2
question
Computers and Technology, 24.06.2019 11:20
Print "censored" if userinput contains the word "darn", else print userinput. end with newline. ex: if userinput is "that darn cat.", then output is: censoredex: if userinput is "dang, that was scary! ", then output is: dang, that was scary! note: if the submitted code has an out-of-range access, the system will stop running the code after a few seconds, and report "program end never reached." the system doesn't print the test case that caused the reported message.#include #include using namespace std; int main() {string userinput; getline(cin, userinput); int ispresent = userinput.find("darn"); if (ispresent > 0){cout < < "censored" < < endl; /* your solution goes here */return 0; }
Answers: 3
You know the right answer?
Write a method for the queue class in the queue. java program (listing 4.4) that displays the conten...
Questions
question
Mathematics, 06.11.2020 17:30
question
Chemistry, 06.11.2020 17:30
Questions on the website: 13722367