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, 22.06.2019 06:30
Exchanging which type of data uses the least bandwidth? music photographs video voice bandwidth- the amount of data that can be moved between two points in a set time period
Answers: 1
question
Computers and Technology, 22.06.2019 17:00
Which of the following is not contained on the slide show toolbar? a. next button b. slide button c. close button d. pen too
Answers: 2
question
Computers and Technology, 23.06.2019 02:00
Arecipients list has been loaded into a document. which commands should be clicked in order to filter the list so that letters will not be printed for recipients who live in a certain state? mailings tab, start mail merge, select recipients, type new list, then insert only contacts from the desired states mailings tab, rules, select recipients, use existing list, then choose a recipients list that includes only contacts in certain states mailings tab, select recipients, use existing list, rules, fill in, then type in certain states mailings tab, rules, skip record select “state” under field name, then type in the state name under “equal to”
Answers: 2
question
Computers and Technology, 23.06.2019 16:00
Helen is having a meeting with her colleagues in her company. they are working on the goals and objectives for the coming year. they want to ensure that these goals and objectives of the processes involved are properly evaluated. which system can helen and her colleagues apply to evaluate this? helen and her colleagues require a blank to evaluate the goals and objectives.
Answers: 2
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
Physics, 19.12.2020 19:00
question
Computers and Technology, 19.12.2020 19:00
question
Chemistry, 19.12.2020 19:00
question
World Languages, 19.12.2020 19:00