Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

image text in transcribed

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

}

Data Structures please complete below code and time complexity Assignment 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Entity Alignment Concepts Recent Advances And Novel Approaches

Authors: Xiang Zhao ,Weixin Zeng ,Jiuyang Tang

1st Edition

9819942527, 978-9819942527

More Books

Students also viewed these Databases questions

Question

What is paper chromatography?

Answered: 1 week ago

Question

Explain the cost of capital.

Answered: 1 week ago

Question

Define capital structure.

Answered: 1 week ago