Question: public class ArrayParkingLane { private char car[]; private final static int MAX = 5; private int size; public ArrayParkingLane() { car = new char[MAX]; size

 public class ArrayParkingLane { private char car[]; private final static intMAX = 5; private int size; public ArrayParkingLane() { car = new

public class ArrayParkingLane { private char car[]; private final static int MAX = 5; private int size; public ArrayParkingLane() { car = new char[MAX]; size = 0; } public int findElement(char key) { int i; for (i=0; i= MAX) System.out.println("Lane already full!!"); else car[size ++] = c; } public void remove(char key) { // Find position of element to be // deleted int pos = findElement(key); if (pos == -1) { System.out.println("Car not found"); return; } // Deleting element int i; for (i=pos; i

} -------------------------------------------

public class LinkedListParkingLane { private Node head; // head of list private static int size = 0; private final static int MAX = 5; /* Linked list Node*/ class Node { char data; Node next; Node(char d) { data = d; next = null; } } /* Appends a new node at the end. This method is defined inside LinkedList class shown above */ public void add(char car) { if(size == MAX) { System.out.println("Lane already full!!"); } /* 1. Allocate the Node & 2. Put in the data 3. Set next as null */ Node new_node = new Node(car); /* 4. If the Linked List is empty, then make the new node as head */ if (head == null) { head = new Node(car); return; } /* 4. This new node is going to be the last node, so make next of it as null */ new_node.next = null; /* 5. Else traverse till the last node */ Node last = head; while (last.next != null) last = last.next; /* 6. Change the next of last node */ last.next = new_node; } /* Given a key, deletes the first occurrence of key in linked list */ public void remove(char key) { // Store head node Node temp = head, prev = null; // If head node itself holds the key to be deleted if (temp != null && temp.data == key) { head = temp.next; // Changed head size --; } // Search for the key to be deleted, keep track of the // previous node as we need to change temp.next while (temp != null && temp.data != key) { prev = temp; temp = temp.next; } // If key was not present in linked list if (temp == null) return; // Unlink the node from linked list prev.next = temp.next; size --; } public void display() { Node tnode = head; while (tnode != null) { System.out.print(tnode.data + " "); tnode = tnode.next; } System.out.println(); }

} ----------------------

import java.util.NoSuchElementException; public class StackParkingLane { private char cars[]; private int top, size; private static final int MAX = 5; /* Constructor for arrayStack */ public StackParkingLane() { size = 0; cars = new char[MAX]; top = -1; } /* Function to check if stack is empty */ public boolean isEmpty() { return top == -1; } /* Function to check if stack is full */ public boolean isFull() { return top == MAX -1 ; } /* Function to get the size of the stack */ public int getSize() { return size ; } /* Function to check the top element of the stack */ public char peek() { if( isEmpty() ) throw new NoSuchElementException("Underflow Exception"); return cars[top]; } /* Function to add an element to the stack */ public void push(char c) { if(size >= MAX) throw new IndexOutOfBoundsException("Overflow Exception"); if(top + 1 = 0; i--) System.out.print(cars[i]+" "); System.out.println(); }

} ---------------------------------

import java.util.NoSuchElementException;

public class QueueParkingLane { private char cars[] ; private int front, rear, size; private static final int MAX = 5; /* Constructor */ public QueueParkingLane() { size = 0; cars = new char[MAX]; front = -1; rear = -1; } /* Function to check if queue is empty */ public boolean isEmpty() { return front == -1; } /* Function to check if queue is full */ public boolean isFull() { return front==0 && rear == MAX -1 ; } /* Function to get the size of the queue */ public int getSize() { return size; } /* Function to check the front element of the queue */ public int peek() { if (isEmpty()) throw new NoSuchElementException("Underflow Exception"); return cars[front]; } /* Function to insert an element to the queue */ public void add(char c) { if (rear == -1) { front = 0; rear = 0; cars[rear] = c; } else if (size >= MAX) throw new IndexOutOfBoundsException("Overflow Exception"); else if ( rear + 1

}

So basically here we want a class to have three structures array,single LinkedList and a stack.we want insert and remove operations on each.lets concentrate on this part:

importjava.util.*;

class Stack{

private :

int arr[];

int top;

int capacity;

Stack(int size)

{

art=new int[size];

capacity=size;

top=-1;

}

public void push(int x)

{

if(isFull()){

System.out.println("Parking full); System.exit(1);}

System.out.println("Inserting"+x);

arr[++top]=x;

}

public int pop(){

if(isEmpty()) System.out.println("Empty');System.exit(1);

System.out.orintln("Removing")+perk());

return arr[top--];}

public int peek(){

if(!isEmpty()) return art[top]; else System.exit(1);return -1}

public int size(){return top+1;}

public Boolean isEmpty(){return top=-1;}

public Boolean isFull(){return top=capacity-1;}

}

class SinglyLInkList

{.

int data;

Node next;

Node(int d){data=d;next=null;}

public void pushkal(int new_data){

Node newnode=new Node(new_data)

newnode.next=head;head=newnode;}

void deleteNode(int pos){if(head==null) return; Node temp=head; if(pos==0){head=temp.next; return; }for(int i=0;temp!=null && i

}

class Array{

static int ind( int ar[],int n,int key){.

for(int I=0;I

static int insert(int ar[],int key,int capacity,int n){

if(n>capacity) return n;

ar[n]=key; return n+1;

}

}

class Main{

public static void main (String[] args){

//Implement all the three classes in this for Inserting and Removing elements using condition al loops.

}

}

Data Structures implement main method Assignment and time complexity please java language Define P; to be a parking lane i in a parking lot and carj to be the jth car; where the number of lanes in a parking lot is 4 and there are 7 cars to park. I

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!