private int [] Array;
private int size;
public ALLINONE(){
Array=new int[5];
size=0;
}
//insertion at the start.
public void insertionStart(int data , int signature){
if(size==5){
System.out.println("Alert ! Memory is full");
System.out.println("Press Any Key to continue..............");
Wait();
Test.ListMenu();
}
else{
for(int i=0 ; i<size-1 ; i++){
Array[i+1]=Array[i];
}
size++;
Array[0]=data;
Display(signature);;
}
}
//insertion in End .
public void InsertionEnd(int data , int signature){
if(size<5){
Array[size++]=data;
System.out.println("Inserted");
Display(signature);
}
else{
System.out.println(" Alert | Memory is Full");
System.out.println("Press Any Key to continue..............");
Wait();
SignatureChecker(signature);
}
}
//insertion at any point.
public void InsertionAny(int data , int Location){
if(Location<size){
Array[Location]=data;
Test.ListMenu();
}
else{
System.out.println("Location is not Found");
System.out.println("Press Any Key to continue..............");
Wait();
Test.ListMenu();
}
}
//Deleting from End.
public void DeleteAtEnd(int signature){
if(size==0){
System.out.println("Alert ! Memory is Empty");
System.out.println("Press Any Key to continue..............");
Wait();
SignatureChecker(signature);
}
else{
size--;
System.out.println("Deleted");
Display(signature);
}
}
//Deletion at Any Point.
public void DeleteAtAnyPoint(int Location){
if(size==0){
System.out.println("Alert ! Memory is Empty");
System.out.println("Press Any Key to continue..............");
Wait();
Test.ListDeletion();
}
else{
for(int i=Location; i<size-1 ; i++){
Array[i]=Array[i+1];
}
size--;
System.out.println("Deleted");
Display(2);
}
}
//Deletion at Start.
public void DeleteStart(int signature){
if(size==0){
System.out.println("Alert ! Memory is Empty");
System.out.println("Press Any Key to continue..............");
Wait();
SignatureChecker(signature);
}
else{
for(int i=0 ; i<size-1 ;i++){
Array[i]=Array[i+1];
}
size--;
System.out.println("Deleted");
Display(signature);
}
}
//Display Numbers.
public void Display(int signature){
if(size==0){
System.out.println("The Memory is Empty : ");
System.out.println("Press Any Key to continue..............");
Wait();
SignatureChecker(signature);
}
else{
System.out.println("Data in Number :");
for(int i=0; i<size ; i++){
System.out.print(Array[i]+"\t");
}
System.out.println("");
System.out.println("Press Any key to continue............... ");
Wait();
SignatureChecker(signature);
}
}
//Getting Size.
public void GetSize(int signature){
if(size==0){
System.out.println("Memory is Empty");
System.out.println("Press Any Key to continue..............");
Wait();
SignatureChecker(signature);
}
else{
System.out.println("Size is :"+size);
System.out.println("Press Any Key to continue..............");
Wait();
SignatureChecker(signature);
}
}
//for top element.
public void Top(){
if(size==0){
System.out.println("Memory is Full");
System.out.println("Press Any Key to continue..............");
Wait();
Test.StackMenu();
}
else{
System.out.println("Top Element is : "+Array[size-1]);
System.out.println("Press Any Key to continue..............");
Wait();
Test.StackMenu();
}
}
//for Clearing Screen.
public void ClearScreen(){
try{
new ProcessBuilder("cmd" , "/c","cls").inheritIO().start().waitFor();
}catch(Exception e){
System.out.println("Unable to Clear Screen");
}
}
//Signature checker.
public static void SignatureChecker(int signature){
switch(signature){
case 0:{
Test.StackMenu();
break;
}
case 1:{
Test.QueueMenu();
break;
}
case 2:{
Test.ListMenu();
break;
}
case 3:{
Test.ListInsertion();
break;
}
case 4:{
Test.ListDeletion();
break;
}
}
}
public void Wait(){
try{
System.in.read();
}catch(Exception x){
System.out.println("Unable to stop Execution");
}
}
}
Main Class:
import java.util.Scanner;
class Test{
static ALLINONE A=new ALLINONE();
static Scanner input=new Scanner(System.in);
public static void main(String[] args){
MainMenu();
}
//Main Menu;
public static void MainMenu(){
A.ClearScreen();
System.out.println("|--<Main Menu>--|");
System.out.println(" 1--> STACK");
System.out.println(" 2--> QUEUE");
System.out.println(" 3--> List ");
System.out.println(" 4--> Exit ");
System.out.println(" Press Key : ");
switch(input.nextInt()){
case 1:{
A.ClearScreen();
StackMenu();
break;
}
case 2:{
A.ClearScreen();
QueueMenu();
break;
}
case 3:{
A.ClearScreen();
ListMenu();
break;
}
case 4:{
System.out.println("Thank You");
A.ClearScreen();
System.exit(0);
break;
}
default:{
A.ClearScreen();
System.out.println("This Type of Option is Not Available");
System.out.println("Press Any Key to continue............");
A.Wait();
A.ClearScreen();
MainMenu();
}
}
}
// Stack Menu signature 0.
public static void StackMenu(){
A.ClearScreen();
System.out.println("|---<Stack Menu >---|");
System.out.println(" 1--> Push");
System.out.println(" 2--> Pop");
System.out.println(" 3--> Top");
System.out.println(" 4--> Size");
System.out.println(" 5--> Display");
System.out.println(" 6--> Back");
System.out.println(" 7--> Exit");
System.out.println(" Press Key : ");
switch(input.nextInt()){
case 1:{
A.ClearScreen();
System.out.println("Push a Number in Stack : ");
A.InsertionEnd(input.nextInt(),0);
break;
}
case 2:{
A.ClearScreen();
A.DeleteAtEnd(0);
break;
}
case 3:{
A.ClearScreen();
A.Top();
break;
}
case 4:{
A.GetSize(0);
break;
}
case 5:{
A.Display(0);
break;
}
case 6 :{
MainMenu();
break;
}
case 7:{
A.ClearScreen();
System.out.println("Thank You");
System.exit(1);
break;
}
default:{
A.ClearScreen();
System.out.println("This Type of Option is Not Available");
System.out.println("Press Any Key to continue..............");
A.Wait();
StackMenu();
break;
}
}
}
// Queue Menu signature 1.
public static void QueueMenu(){
A.ClearScreen();
System.out.println("|---<Queue Menu >---|");
System.out.println(" 1--> Insert");
System.out.println(" 2--> Delete");
System.out.println(" 3--> Display");
System.out.println(" 4--> Back");
System.out.println(" 5--> Exit");
System.out.println(" Press Key : ");
switch(input.nextInt()){
case 1:{
A.ClearScreen();
System.out.print("Enter Number : ");
A.InsertionEnd(input.nextInt(),1);
break;
}
case 2:{
A.ClearScreen();
A.DeleteStart(1);
break;
}
case 3:{
A.ClearScreen();
A.Display(1);
break;
}
case 4:{
A.ClearScreen();
MainMenu();
break;
}
case 5:{
A.ClearScreen();
System.out.println("Thank You");
System.exit(1);
break;
}
default:{
A.ClearScreen();
System.out.println("This Type of Option is Not Available");
System.out.println("Press Any Key to continue..............");
A.Wait();
QueueMenu();
break;
}
}
}
// List Menu signature 2.
public static void ListMenu(){
A.ClearScreen();
System.out.println("|---<List Menu >---|");
System.out.println(" 1--> Insert");
System.out.println(" 2--> Delete");
System.out.println(" 3--> Display");
System.out.println(" 4--> Back");
System.out.println(" 5--> Exit");
switch(input.nextInt()){
case 1:{
A.ClearScreen();
ListInsertion();
break;
}
case 2:{
A.ClearScreen();
ListDeletion();
break;
}
case 3:{
A.ClearScreen();
A.Display(2);
break;
}
case 4:{
A.ClearScreen();
MainMenu();
break;
}
case 5:{
A.ClearScreen();
System.out.println("Thank You");
System.exit(0);
break;
}
default:{
A.ClearScreen();
System.out.println("This Type of Option is Not Available");
System.out.println("Press Any Key to continue..............");
A.Wait();
A.ClearScreen();
ListMenu();
break;
}
}
}
//List Insertion Menu. signature is 3
public static void ListInsertion(){
System.out.println("|---<Insertion Menu >---|");
System.out.println(" 1--> Insertion At Any Point");
System.out.println(" 2--> Insertion At starting");
System.out.println(" 3--> Insertion At Ending ");
System.out.println(" 4--> Back");
System.out.println(" 5--> Exit");
System.out.println(" Press Key : ");
switch(input.nextInt()){
case 1:{
A.ClearScreen();
System.out.println("Enter Data First and 2nd Location :");
A.InsertionAny(input.nextInt(), input.nextInt());
break;
}
case 2:{
A.ClearScreen();
A.insertionStart(input.nextInt(),3);
break;
}
case 3:{
A.ClearScreen();
A.InsertionEnd(input.nextInt(),3);
break;
}
case 4:{
A.ClearScreen();
ListMenu();
break;
}
case 5:{
A.ClearScreen();
System.exit(0);
break;
}
default:{
A.ClearScreen();
System.out.println("This Type of Option is Not Available");
System.out.println("Press Any Key to continue..............");
A.Wait();
A.ClearScreen();
ListInsertion();
break;
}
}
}
//List Deletion Menu. signature is 4
public static void ListDeletion(){
A.ClearScreen();
System.out.println(" |---<Deletion Menu >---|");
System.out.println(" 1--> Delete At Any Point");
System.out.println(" 2--> Delete At starting");
System.out.println(" 3--> Delete At Ending ");
System.out.println(" 4--> Back");
System.out.println(" 5--> Exit");
System.out.println(" Press Key : ");
switch(input.nextInt()){
case 1:{
A.ClearScreen();
A.DeleteAtAnyPoint(input.nextInt());
break;
}
case 2:{
A.ClearScreen();
A.DeleteStart(4);
break;
}
case 3:{
A.ClearScreen();
A.DeleteAtEnd(4);
break;
}
case 4:{
A.ClearScreen();
ListMenu();
break;
}
case 5:{
A.ClearScreen();
System.exit(0);
break;
}
default:{
A.ClearScreen();
System.out.println("This Type of Option is Not Available");
System.out.println("Press Any Key to continue..............");
A.Wait();
A.ClearScreen();
ListDeletion();
break;
}
}
}
}
No comments:
Post a Comment