blackboard9.wju.edu ents-2017FA-CSC-222-01 Home | Chegg.com 1 1 UNIVERSITY ts An
ID: 3890611 • Letter: B
Question
blackboard9.wju.edu ents-2017FA-CSC-222-01 Home | Chegg.com 1 1 UNIVERSITY ts Announcements Study guide for Monday's test Posted on: Friday, September 22, 2017 208:34 PM EDT The test is worth 100 points (40 short answer, 40 problem solving, and 20 open-book programm ing+ 10XC) Be able to decide the best data structure for a particular application - Know the complexities (.e. Big-0) of the various stack/queue algorithms - Know what node-number and key-field lookups entail - Know what a restricted data structure is Be able to describe the various linked lists we have discussed Be able to write a Java class that uses an ArrayList as its basic data structure -Be able to write a Node class for any of the linked lists we have discussed - Know how to insert and delete from the various linked ists we have discussed Be able to write Java code to implement various functions of stacks and queuesExplanation / Answer
What is linked list: A linked list is defined as a collection of nodes. A linked list consists of series of structures, which are not necessarily contiguous. Each structure contains one or more than one contiguous information fields and a pointer to a structure containing its successor.
Linked list types are:
1) Single linked list
A single linked list is a linear collection of data elements, called nodes. The linear order is given by means of pointers.
2) Double linked list
The problem with single linked list:
We cannot access the predecessor of node from the current node.
Solution:
A double linked list is one in which all nodes are linked together by multiple links which help in accessing both the successor (next) node and predecessor (previous) node for any arbitrary node within the list. It provides bi-directional traversing.
3) Circular linked list
Circular linked list has no beginning and no end. A single linked list can be made a circular linked list by simply storing the address of the very first node in the link field of the last node. It is just a singly linked list in which the link field of the last node contains the address of the first node of the list. The link field of the last node does not point to NULL rather it points back to the beginning of the linked list. A circular linked list has no end. Therefore, it is necessary to establish the FIRST and LAST nodes.
4) Double circular linked list
A circular doubly linked list is one which has both the successor pointer and predecessor pointer in circular manner. Circular doubly linked lists are the variation of doubly linked lists.
//Array List
import java.util.*;
//Class ArrayListExample definition
public class ArrayListExample
{
//Main method definition
public static void main(String args[])
{
//Creation of ArrayList of type string
ArrayList<String> arrayListObj = new ArrayList<String>();
//add method is used to add elements to the array list
//arrayListObj is the ArrayList object
arrayListObj.add("LUX");
arrayListObj.add("Cinthod");
arrayListObj.add("Dove");
arrayListObj.add("Liril");
//Displaying array list elements
System.out.println(" Currently the array list has following soap names: " + arrayListObj);
//Add an element at the specified index position
arrayListObj.add(1, "Rexona");
//Displaying array list elements after insertion
System.out.println(" Currently the array list after insertion: " + arrayListObj);
//Remove an elements from array list with specified name
arrayListObj.remove("Dove");
//Displays the array list contents after delete operation with specified name
System.out.println(" Current array list after deletion element name:" + arrayListObj);
//Remove an element from the array list with specified index position
arrayListObj.remove(2);
//Displays the array list contents after delete operation with index position
System.out.println(" Current array list after deletion index :" + arrayListObj);
}//End of method main
}//End of class
Sample Run:
Currently the array list has following soap names: [LUX, Cinthod, Dove, Liril]
Currently the array list after insertion: [LUX, Rexona, Cinthod, Dove, Liril]
Current array list after deletion element name:[LUX, Rexona, Cinthod, Liril]
Current array list after deletion index :[LUX, Rexona, Liril]
Single Liniked List
import java.util.Scanner;
//Class Node definition
class Node
{
//Instance variable to store value of type integer
protected int value;
//Node class object created to store its own reference
//Instance variable to point to a node
protected Node linkNode;
//Default constructor to initialize
public Node()
{
//Object is initialized to null
linkNode = null;
//Value is initialized to zero
value = 0;
}//End of constructor
//Parameterized constructor to initialize with specific value
public Node(int d,Node n)
{
//value is assigned with d value
value = d;
//Points to new node
linkNode = n;
}//End of constructor
//Method to set link to next Node
public void setLink(Node n)
{
linkNode = n;
}//End of method
//Method to set data to current Node
public void setData(int d)
{
value = d;
}//End of method
//Method to get link to next node
public Node getLink()
{
//Returns the current reference
return linkNode;
}//End of method
//Method to get data from current Node
public int getData()
{
//Return the current node data
return value;
}//End of method
}//End of class
//Class linkedList definition
class linkedList
{
//Reference object to point to starting node
protected Node start;
//Reference object to point to last node
protected Node end ;
//To store the size of the list
public int size ;
//Default constructor to initialize
public linkedList()
{
//Start and last object is initialized to null
start = null;
end = null;
//Size is initialized to zero
size = 0;
}//End of constructor
//Method to check if list is empty
public boolean isEmpty()
{
//Returns true if the list is empty
return start == null;
}//End of method
//Method to return the size of list
public int getSize()
{
//Returns the size of the list
return size;
}//End of method
//Method to insert an element at starting position
public void insertAtStart(int val)
{
//Creates a new node
Node newNode = new Node(val, null);
//Increases the size by one
size++ ;
//Checks if start is null then it is the first node
if(start == null)
{
//Start is pointing to new node
start = newNode;
//End node refers to start node
end = start;
}//End of if
//If it is not the first node
else
{
//Start pointing to new node
newNode.setLink(start);
//New node is assign to start node
start = newNode;
}//End of else
}//End of method
//Method to insert a node at the end
public void insertAtEnd(int val)
{
//Creates a new node
Node newNode = new Node(val, null);
//Increases the size by one
size++ ;
//Checks if start is null then it is the first node
if(start == null)
{
//Start is pointing to new node
start = newNode;
//End node refers to start node
end = start;
}//End of if
else
{
//end pointing to new node
end.setLink(newNode);
//New node reference to end node
end = newNode;
}//End of else
}//End of method
//Method to insert an element at a specified position
public void insertAtPos(int val , int pos)
{
//Creates a new node
Node newNode = new Node(val, null);
//Creates temporary start reference and refers to start
Node startPtr = start;
//Position is decreased to one because it starts from zero
pos = pos - 1 ;
//Loops till end of the size of list
for (int counter = 1; counter < size; counter++)
{
//Checks if counter value is equal to specified position
if (counter == pos)
{
//Temporary reference points to next node
Node tmpNode = startPtr.getLink() ;
//Start refers to the new node
startPtr.setLink(newNode);
//New node refers to temporary node
newNode.setLink(tmpNode);
//Come out of the loop
break;
}//End of method
startPtr = startPtr.getLink();
}//End of for loop
//Increase the size by one
size++ ;
}//End of method
//Method to delete a node at position
public void deleteAtPos(int pos)
{
//Checks if the specified position is one for starting node
if (pos == 1)
{
start = start.getLink();
//size is reduced by one
size--;
return ;
}//End of if
//Checks if the position is equal to size for last node
if (pos == size)
{
//Creates a reference to refer to start node
Node sNode = start;
//Creates a temporary reference to refer to start node
Node tNode = start;
//Loops till end of the list
while (sNode != end)
{
//Assigns start node reference to temporary node
tNode = sNode;
//Points to next node
sNode = sNode.getLink();
}//End of while loop
//Temporary node reference is assigned to end node
end = tNode;
//End points to null
end.setLink(null);
//Reduce the size by one
size --;
return;
}//End of if
//For other than first or last
//Creates a reference to start node
Node ptr = start;
//Decrease the position by one because it starts from zero
pos = pos - 1 ;
//Loops till end of list
for (int counter = 1; counter < size - 1; counter++)
{
//Checks if the counter value is equal to position specified
if (counter == pos)
{
//Creates a temporary reference refers to next node
Node tmpNode = ptr.getLink();
//Temporary node refers to next node
tmpNode = tmpNode.getLink();
ptr.setLink(tmpNode);
break;
}//End of if
ptr = ptr.getLink();
}//End of for loop
//Decrease the size by one
size-- ;
}//End of method
//Method to display elements of the list
public void display()
{
System.out.print(" Singly Linked List = ");
//Checks if the size is zero
if (size == 0)
{
//Displays the error message empty
System.out.print("ERROR: Empty list ");
return;
}//End of if
//If only one node
if (start.getLink() == null)
{
//Displays the node value
System.out.println(start.getData() );
return;
}//End of if
//Creates a temporary reference to refer to start node
Node tempNode = start;
//Display the value of the start node
System.out.print(start.getData()+ "->");
//Points to the next node
tempNode = start.getLink();
//Loops till not null
while (tempNode.getLink() != null)
{
//Display the value of the current node
System.out.print(tempNode.getData()+ "->");
//Points to the next node
tempNode = tempNode.getLink();
}//End of while loop
System.out.print(tempNode.getData()+ " ");
}//End of method
}//End of class
//Class SinglyLinkedList definition
public class SingleLinkedList
{
//main method definition
public static void main(String[] args)
{
//Scanner class object to accept data
Scanner scan = new Scanner(System.in);
//Creating object of class linkedList
linkedList list = new linkedList();
System.out.println("Singly Linked List Test ");
//To store user choice
char ch;
//Loops till user choice is Y or y
do
{
//Displays menu
System.out.println(" Singly Linked List Operations ");
System.out.println("1. Insert at the begining");
System.out.println("2. Insert at the end");
System.out.println("3. Insert at the specified position");
System.out.println("4. Delete at the specified position");
System.out.println("5. Check empty list");
System.out.println("6. Display size");
System.out.println("Enter your choice: ");
//Accepts user choice
int choice = scan.nextInt();
//Switch case begins
switch (choice)
{
case 1 :
System.out.println("Enter integer element to insert");
list.insertAtStart( scan.nextInt() );
break;
case 2 :
System.out.println("Enter integer element to insert");
list.insertAtEnd( scan.nextInt() );
break;
case 3 :
System.out.println("Enter integer element to insert");
int num = scan.nextInt() ;
System.out.println("Enter position");
int pos = scan.nextInt() ;
if (pos <= 1 || pos > list.getSize() )
System.out.println("Invalid position ");
else
list.insertAtPos(num, pos);
break;
case 4 :
System.out.println("Enter position");
int p = scan.nextInt() ;
if (p < 1 || p > list.getSize() )
System.out.println("Invalid position ");
else
list.deleteAtPos(p);
break;
case 5 :
System.out.println("Empty status = "+ list.isEmpty());
break;
case 6 :
System.out.println("Size = "+ list.getSize() +" ");
break;
default :
System.out.println("Wrong Entry ");
break;
}//End of switch case
/* Display List */
list.display();
System.out.println(" Do you want to continue (Type y or n) ");
ch = scan.next().charAt(0);
} while (ch == 'Y'|| ch == 'y');
System.out.println(" ********** Thank you ************* ");
}//End of main method
}//End of class
Sample Run:
Singly Linked List Test
Singly Linked List Operations
1. Insert at the begining
2. Insert at the end
3. Insert at the specified position
4. Delete at the specified position
5. Check empty list
6. Display size
Enter your choice: 1
Enter integer element to insert 10
Singly Linked List = 10
Do you want to continue (Type y or n) y
Singly Linked List Operations
1. Insert at the begining
2. Insert at the end
3. Insert at the specified position
4. Delete at the specified position
5. Check empty list
6. Display size
Enter your choice: 1
Enter integer element to insert 20
Singly Linked List = 20->10
Do you want to continue (Type y or n) y
Singly Linked List Operations
1. Insert at the begining
2. Insert at the end
3. Insert at the specified position
4. Delete at the specified position
5. Check empty list
6. Display size
Enter your choice: 1
Enter integer element to insert 5
Singly Linked List = 5->20->10
Do you want to continue (Type y or n) y
Singly Linked List Operations
1. Insert at the begining
2. Insert at the end
3. Insert at the specified position
4. Delete at the specified position
5. Check empty list
6. Display size
Enter your choice: 2
Enter integer element to insert 40
Singly Linked List = 5->20->10->40
Do you want to continue (Type y or n) y
Singly Linked List Operations
1. Insert at the begining
2. Insert at the end
3. Insert at the specified position
4. Delete at the specified position
5. Check empty list
6. Display size
Enter your choice:
3
Enter integer element to insert
35
Enter position2
Singly Linked List = 5->35->20->10->40
Do you want to continue (Type y or n) y
Singly Linked List Operations
1. Insert at the begining
2. Insert at the end
3. Insert at the specified position
4. Delete at the specified position
5. Check empty list
6. Display size
Enter your choice: 5
Empty status = false
Singly Linked List = 5->35->20->10->40
Do you want to continue (Type y or n) y
Singly Linked List Operations
1. Insert at the begining
2. Insert at the end
3. Insert at the specified position
4. Delete at the specified position
5. Check empty list
6. Display size
Enter your choice: 6
Size = 5
Singly Linked List = 5->35->20->10->40
Do you want to continue (Type y or n) n
********** Thank you *************
Stack
import java.util.*;
//Class arrayStack definition
class arrayStack
{
//Declares an integer array to store values
protected int arr[];
//Instance variables to store the top position
protected int top;
//Instance variables to store the size of the stack (maximum length of the stack)
protected int size;
//Instance variables to store length of the stack (currently number of element)
protected int len;
//Parameterized constructor for arrayStack
public arrayStack(int n)
{
//Parameter value n is assigned to size
size = n;
//length is assigned to zero
len = 0;
//Creates an array of specified maximum size
arr = new int[size];
//Top position is assigned to -1 initially
top = -1;
}//End of constructor
//Method to check if stack is empty
public boolean isEmpty()
{
//returns true if top is -1
return top == -1;
}//End of method
//Method to check if stack is full
public boolean isFull()
{
//returns true if top is equal to one less than size, because starts from zero
return top == size -1 ;
}//End of method
//Method to get the size of the stack
public int getSize()
{
return len ;
}//End of method
//Method to check the top element of the stack
public int peek()
{
//Checks for empty if empty throws an exception
if( isEmpty() )
throw new NoSuchElementException("Underflow Exception");
//Otherwise returns stack top position value
return arr[top];
}//End of method
//Method to add an element to the stack
public void push(int data)
{
//Checks if top plus one position is greater than or equals to the size throws an exception
if(top + 1 >= size)
throw new IndexOutOfBoundsException("Overflow Exception");
//Checks if top plus one position is greater than to the size throws an exception
if(top + 1 < size )
//Increase the top position by one and stores the data
arr[++top] = data;
//Increase the current length by one
len++ ;
}//End of method
//Method to delete an element from the stack
public int pop()
{
//Checks for empty if empty throws an exception
if( isEmpty() )
throw new NoSuchElementException("Underflow Exception");
//Otherwise decrease the current length by one
len-- ;
//Returns the current stack position value and decrease the top by one
return arr[top--];
}//End of method
//Method to display the status of the stack
public void display()
{
System.out.print(" Stack Contents : ");
//Checks if the current length of the stack is zero display error message
if (len == 0)
{
//Displays the error message
System.out.print("Stack is empty ");
return ;
}//End of if
//Loops till end of the stack
for (int counter = top; counter >= 0; counter--)
//Displays the stack contents
System.out.print(arr[counter]+" ");
System.out.println();
}//End of method
}//End of class
//Class StackImplement definition
public class StackImplementation
{
//main method definition
public static void main(String[] args)
{
//Scanner class object created to accept user data
Scanner scan = new Scanner(System.in);
//Accepts the maximum length of the stack
System.out.println("Enter Size of Integer Stack ");
int n = scan.nextInt();
//Creating object of class arrayStack
arrayStack stk = new arrayStack(n);
//To store user choice
char ch;
//Loops until user choice is Y or y
do
{
//Displays menu
System.out.println(" ************ Stack Operations *********** ");
System.out.println("1. Push");
System.out.println("2. Pop");
System.out.println("3. Peek");
System.out.println("4. Check for empty");
System.out.println("5. Check full");
System.out.println("6. Display size");
System.out.println("Enter you choice: ");
//Accepts user choice
int choice = scan.nextInt();
//Switch - case begins
switch (choice)
{
case 1 :
System.out.println("Enter integer element to push: ");
try
{
stk.push( scan.nextInt() );
}
catch (Exception e)
{
System.out.println("Error : " + e.getMessage());
}
break;
case 2 :
try
{
System.out.println("Popped Element = " + stk.pop());
}
catch (Exception e)
{
System.out.println("Error : " + e.getMessage());
}
break;
case 3 :
try
{
System.out.println("Peek Element = " + stk.peek());
}
catch (Exception e)
{
System.out.println("Error : " + e.getMessage());
}
break;
case 4 :
System.out.println("Empty status = " + stk.isEmpty());
break;
case 5 :
System.out.println("Full status = " + stk.isFull());
break;
case 6 :
System.out.println("Size = " + stk.getSize());
break;
default :
System.out.println("Wrong Entry ");
break;
}//End of switch - case
//Display stack
stk.display();
System.out.println(" Do you want to continue (Type y or n) ");
ch = scan.next().charAt(0);
} while (ch == 'Y'|| ch == 'y');
}//End of main method
}//End of class
Sample Run:
Enter Size of Integer Stack 3
************ Stack Operations ***********
1. Push
2. Pop
3. Peek
4. Check for empty
5. Check full
6. Display size
Enter you choice: 1
Enter integer element to push: 10
Stack Contents : 10
Do you want to continue (Type y or n) y
************ Stack Operations ***********
1. Push
2. Pop
3. Peek
4. Check for empty
5. Check full
6. Display size
Enter you choice: 1
Enter integer element to push: 20
Stack Contents : 20 10
Do you want to continue (Type y or n) y
************ Stack Operations ***********
1. Push
2. Pop
3. Peek
4. Check for empty
5. Check full
6. Display size
Enter you choice: 1
Enter integer element to push: 30
Stack Contents : 30 20 10
Do you want to continue (Type y or n) y
************ Stack Operations ***********
1. Push
2. Pop
3. Peek
4. Check for empty
5. Check full
6. Display size
Enter you choice: 1
Enter integer element to push: 40
Error : Overflow Exception
Stack Contents : 30 20 10
Do you want to continue (Type y or n) y
************ Stack Operations ***********
1. Push
2. Pop
3. Peek
4. Check for empty
5. Check full
6. Display size
Enter you choice: 5
Full status = true
Stack Contents : 30 20 10
Do you want to continue (Type y or n) y
************ Stack Operations ***********
1. Push
2. Pop
3. Peek
4. Check for empty
5. Check full
6. Display size
Enter you choice: 2
Popped Element = 30
Stack Contents : 20 10
Do you want to continue (Type y or n) y
************ Stack Operations ***********
1. Push
2. Pop
3. Peek
4. Check for empty
5. Check full
6. Display size
Enter you choice: 2
Popped Element = 20
Stack Contents : 10
Do you want to continue (Type y or n) y
************ Stack Operations ***********
1. Push
2. Pop
3. Peek
4. Check for empty
5. Check full
6. Display size
Enter you choice: 2
Popped Element = 10
Stack Contents : Stack is empty
Do you want to continue (Type y or n) y
************ Stack Operations ***********
1. Push
2. Pop
3. Peek
4. Check for empty
5. Check full
6. Display size
Enter you choice: 4
Empty status = true
Stack Contents : Stack is empty
Do you want to continue (Type y or n) y
************ Stack Operations ***********
1. Push
2. Pop
3. Peek
4. Check for empty
5. Check full
6. Display size
Enter you choice: 6
Size = 0
Stack Contents : Stack is empty
Do you want to continue (Type y or n) n
Queue
import java.util.*;
//Class arrayQueue definition
class arrayQueue
{
//Declares an array
protected int data[] ;
//To store the front position
protected int front;
//To store the rear position
protected int rear;
//To store the maximum length
protected int size;
//To store the current length
protected int len;
//Parameterized Constructor
public arrayQueue(int n)
{
//Assigns the specified size in n to size
size = n;
//Initializes length to zero
len = 0;
//Creates an array with specified size
data = new int[size];
//Initializes the front to -1
front = -1;
//Initializes the rear to -1
rear = -1;
}//End of constructor
//Method to check if queue is empty
public boolean isEmpty()
{
//returns true if front is -1
return front == -1;
}//End of method
//Method to check if queue is full
public boolean isFull()
{
//returns if front is zero and rear is equal to one minus to the size
return front==0 && rear == size -1 ;
}//End of method
//Method to get the size of the queue
public int getSize()
{
//returns the current length of the queue
return len ;
}//End of method
//Method to check the front element of the queue
public int peek()
{
//Checks if queue is empty throws an exception
if (isEmpty())
throw new NoSuchElementException("Underflow Exception");
//Otherwise returns the data at the front of the queue
return data[front];
}//End of method
//Method to insert an element to the queue
public void insert(int value)
{
//Checks if rear is -1 then first item
if (rear == -1)
{
//Initializes front and rear to zero
front = 0;
rear = 0;
//Assigns value at rear position of the queue
data[rear] = value;
}//End of if
//Checks if one added to rear is greater than or equal to the size then throw an exception
else if (rear + 1 >= size)
throw new IndexOutOfBoundsException("Overflow Exception");
//Otherwise checks if one added to rear is greater than the size then throw an exception
else if ( rear + 1 < size)
//Increase the rear position by one and assigns value to the rear position of the queue
data[++rear] = value;
//Increase the current length by one
len++ ;
}//End of method
//Method to remove front element from the queue
public int remove()
{
//Checks if queue is empty throws an exception
if (isEmpty())
throw new NoSuchElementException("Underflow Exception");
//Otherwise
else
{
//Decrease the current length by one
len-- ;
//Store the data at the front of the queue
int element = data[front];
//Checks if front is equal to rear only one item to delete
if ( front == rear)
{
//Assigns front and rear to -1 for empty
front = -1;
rear = -1;
}//End of if
//Otherwise increase the front by one
else
front++;
//Return the deleted value
return element;
}//End of else
}//End of method
//Method to display the status of the queue
public void display()
{
System.out.print(" Queue: ");
//Checks if the current length of the stack is zero display error message
if (len == 0)
{
System.out.print("Queue is empty ");
return ;
}//End of if
//Loops till end of the queue
for (int counter = front; counter <= rear; counter++)
//Display the value at current position
System.out.print(data[counter]+" ");
System.out.println();
}//End of method
}//End of class
//Class QueueImplement definition
public class QueueImplementation
{
//main method definition
public static void main(String[] args)
{
//Scanner class object created to accept data
Scanner scan = new Scanner(System.in);
//Accepts the size of the queue
System.out.println("Enter Size of Integer Queue ");
int n = scan.nextInt();
//Creating object of class arrayQueue
arrayQueue q = new arrayQueue(n);
//To store user choice
char ch;
//Loops until user choice is Y or y
do
{
System.out.println(" ***************** Queue Operations ****************");
System.out.println("1. Insert");
System.out.println("2. Remove");
System.out.println("3. Peek");
System.out.println("4. Check Empty");
System.out.println("5. Check Full");
System.out.println("6. Display Dize");
//Accepts user choice
System.out.println("Enter your choice: ");
int choice = scan.nextInt();
//Switch - case begins
switch (choice)
{
case 1 :
System.out.println("Enter integer element to insert: ");
try
{
q.insert( scan.nextInt() );
}
catch(Exception e)
{
System.out.println("Error : " +e.getMessage());
}
break;
case 2 :
try
{
System.out.println("Removed Element = "+q.remove());
}
catch(Exception e)
{
System.out.println("Error : " +e.getMessage());
}
break;
case 3 :
try
{
System.out.println("Peek Element = "+q.peek());
}
catch(Exception e)
{
System.out.println("Error : "+e.getMessage());
}
break;
case 4 :
System.out.println("Empty status = "+q.isEmpty());
break;
case 5 :
System.out.println("Full status = "+q.isFull());
break;
case 6 :
System.out.println("Size = "+ q.getSize());
break;
default : System.out.println("Wrong Entry ");
break;
}//End of switch - case
//Display Queue contents
q.display();
System.out.println(" Do you want to continue (Type y or n) ");
ch = scan.next().charAt(0);
} while (ch == 'Y'|| ch == 'y');
}//End of main method
}//End of class
Sample Run:
Enter Size of Integer Queue
3
***************** Queue Operations ****************
1. Insert
2. Remove
3. Peek
4. Check Empty
5. Check Full
6. Display Dize
Enter your choice:
1
Enter integer element to insert:
10
Queue: 10
Do you want to continue (Type y or n)
y
***************** Queue Operations ****************
1. Insert
2. Remove
3. Peek
4. Check Empty
5. Check Full
6. Display Dize
Enter your choice:
1
Enter integer element to insert:
20
Queue: 10 20
Do you want to continue (Type y or n)
y
***************** Queue Operations ****************
1. Insert
2. Remove
3. Peek
4. Check Empty
5. Check Full
6. Display Dize
Enter your choice:
1
Enter integer element to insert:
30
Queue: 10 20 30
Do you want to continue (Type y or n)
y
***************** Queue Operations ****************
1. Insert
2. Remove
3. Peek
4. Check Empty
5. Check Full
6. Display Dize
Enter your choice:
1
Enter integer element to insert:
40
Error : Overflow Exception
Queue: 10 20 30
Do you want to continue (Type y or n)
y
***************** Queue Operations ****************
1. Insert
2. Remove
3. Peek
4. Check Empty
5. Check Full
6. Display Dize
Enter your choice:
5
Full status = true
Queue: 10 20 30
Do you want to continue (Type y or n)
y
***************** Queue Operations ****************
1. Insert
2. Remove
3. Peek
4. Check Empty
5. Check Full
6. Display Dize
Enter your choice:
2
Removed Element = 10
Queue: 20 30
Do you want to continue (Type y or n)
y
***************** Queue Operations ****************
1. Insert
2. Remove
3. Peek
4. Check Empty
5. Check Full
6. Display Dize
Enter your choice:
2
Removed Element = 20
Queue: 30
Do you want to continue (Type y or n)
y
***************** Queue Operations ****************
1. Insert
2. Remove
3. Peek
4. Check Empty
5. Check Full
6. Display Dize
Enter your choice:
3
Peek Element = 30
Queue: 30
Do you want to continue (Type y or n)
y
***************** Queue Operations ****************
1. Insert
2. Remove
3. Peek
4. Check Empty
5. Check Full
6. Display Dize
Enter your choice:
3
Peek Element = 30
Queue: 30
Do you want to continue (Type y or n)
y
***************** Queue Operations ****************
1. Insert
2. Remove
3. Peek
4. Check Empty
5. Check Full
6. Display Dize
Enter your choice:
2
Removed Element = 30
Queue: Queue is empty
Do you want to continue (Type y or n)
y
***************** Queue Operations ****************
1. Insert
2. Remove
3. Peek
4. Check Empty
5. Check Full
6. Display Dize
Enter your choice:
3
Error : Underflow Exception
Queue: Queue is empty
Do you want to continue (Type y or n)
y
***************** Queue Operations ****************
1. Insert
2. Remove
3. Peek
4. Check Empty
5. Check Full
6. Display Dize
Enter your choice:
4
Empty status = true
Queue: Queue is empty
Do you want to continue (Type y or n)
y
***************** Queue Operations ****************
1. Insert
2. Remove
3. Peek
4. Check Empty
5. Check Full
6. Display Dize
Enter your choice:
6
Size = 0
Queue: Queue is empty
Do you want to continue (Type y or n)
y
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.