Java programming  I have to do the "Resize method" which I believe if the array is full, it should resize so there is space.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Java programming 

I have to do the "Resize method" which I believe if the array is full, it should resize so there is space.

Ill paste the code below: 

package circularQueue;

 

/*

 * Design the class that would implement the interfaceiQueue. 

 */

public class cirQueue <T> implements iQueue <T> {

//Array of T objects 

private T[] Ar; //reference to array of objects 

//int size keeps track of how many elements in the queue

int size = 0;

//first the index to the head of the queue

int first = -1;

//last the index the last element of the queue

int last = -1;

 

public cirQueue() {

Ar = (T[]) new Object[5];

size = 0;

first = last = -1;

}

public int size() {

return size;

}

public boolean empty() {

return (size == 0);

}

private void resize() {

//HW TODO

}

//inserts element e at the back of the queue

public void insert(T e) {

if(this.empty()) {

first = last = 0;

//insert e at indx 0;

Ar[first] = e;

size = 1;

return;

}

if(size == Ar.length) {

//resize HW complete this one. 

this.resize();

}

//increase last by one, make sure it circulate back to 0 if it reaches capacity-1

last = (last + 1) % Ar.length;

//insert e at index last 

Ar[last] = e;

//increase the size 

size++;

}

public T remove() {

if(this.empty()) {

System.out.println("Error empty queue");

return null;

}

T save = Ar[first];

first = (first + 1) % Ar.length;

size--;

return save;

}

 

public String toString() {

if(this.empty())

return "[]";

String st = "[";

//build your string [-1, -3, -9]

int temp = first;

for(int i = 0; i < size-1; i++) {

//in the loop your are always dealing with element i

//v element i is Ar[i]

//append Ar[i], to the string

st += Ar[temp].toString() + ", ";

temp = (temp + 1) % Ar.length;

}

//close the bracket 

st += Ar[temp].toString() + "]";

return st;

}

 

}

import java.util.ArrayList;I
public class Tester {
public static void main(String [] args) {
Stack<String> st = new Stack<String>();
st.push("st");
st.push ("sfsf");
st.push("hi");
System.out.println("size:
System.out.println("removing:
System.out.println("size:
System.out.println("the top is: " + st.peek ());
System.out.println("size: " + st.size()+
+ st.size() +
+ st.pop());
+ st.size()+
St:
+ st.toString());
%3D
" St: " + st.toString());
St:
+ st.toString());
Queue<Integer> Q = new LinkedList<Integer>();
Q.add(-4);
}
}
Transcribed Image Text:import java.util.ArrayList;I public class Tester { public static void main(String [] args) { Stack<String> st = new Stack<String>(); st.push("st"); st.push ("sfsf"); st.push("hi"); System.out.println("size: System.out.println("removing: System.out.println("size: System.out.println("the top is: " + st.peek ()); System.out.println("size: " + st.size()+ + st.size() + + st.pop()); + st.size()+ St: + st.toString()); %3D " St: " + st.toString()); St: + st.toString()); Queue<Integer> Q = new LinkedList<Integer>(); Q.add(-4); } }
private void resize() {
//HW_TODO
}
Transcribed Image Text:private void resize() { //HW_TODO }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY