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 14:40
You are working with a professional edition organization. they wish to install the expense tracker which requires the use of 4 custom tabs, 3 custom objects, and one custom app. if the company is already using 4 applications, 36 custom objects, and 7 custom tabs, what will happen when they try to install expense tracker?
Answers: 1
question
Computers and Technology, 22.06.2019 17:30
Where would you click to edit the chart data?
Answers: 1
question
Computers and Technology, 22.06.2019 22:20
Avariable of the data type arrays is storing 10 quantities. what is true about these quantities? a. the quantities all have different characteristics. b. the quantities all have the same characteristics. c. five quantities have the same and five have different characteristics. d. it is necessary for all quantities to be integers. e. it is necessary for all quantities to be characters.
Answers: 2
question
Computers and Technology, 22.06.2019 23:30
Creating "smart interfaces" in all sectors of industry, government, and the public arena is one of the fastest growing hct areas. these interfaces model, interpret, and analyze such human characteristics as speech, gesture, and vision. the field of biometrics, in which humans authenticate themselves to machines, is an area of considerable interest to hct practitioners. fingerprint scans are one of the most frequently used biometric options, and this article, biometric student identification: practical solutions for accountability & security in schools, makes a case for the implementation of fingerprint scans in schools. critique the article, and answer the following questions: according to the author, what are the main benefits of adopting fingerprint scans in schools for student identification? according to the author, what are the main drawbacks of adopting fingerprint scans in schools for student identification? do you agree with the author's assessment of the pl
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, 22.02.2020 14:50
question
Physics, 22.02.2020 14:50
question
English, 22.02.2020 15:14
question
English, 22.02.2020 15:16
question
Mathematics, 22.02.2020 15:18
question
Mathematics, 22.02.2020 15:22
question
Mathematics, 22.02.2020 15:22
Questions on the website: 13722363