Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement a HashMap Implement a stack by using a deque Define a link list Define

ID: 3850821 • Letter: I

Question

Implement a HashMap Implement a stack by using a deque Define a link list Define a queue Implement a comparable interface Vocabulary: Identify the vocabulary word for each definition below. A double-ended queue: a queue that can add and remove elements to the front or back of the list. The links of a LinkedList. An interface used to define a group of objects. This includes lists and sets. Maps that link a Key to a Value and may have duplicate Keys but cannot have duplicate Values. A list of elements that is dynamically stored. A list of elements with a first in first out ordering.

Explanation / Answer

For MAP

import java.util.*;
public class mapDemo {

public static void main(String[] args) {
Map m1 = new HashMap();
// Map of name and their age
m1.put("Mantu", 15);
m1.put("Rashmi", 31);
m1.put("Ayan", 12);
System.out.println(" Map Elements are : ");
System.out.print(" " + m1);
}
}


For Stack using Deque

import java.util.ArrayDeque;
import java.util.Deque;

public class IntegerStack {
private Deque<Integer> Stack = new ArrayDeque<Integer>();

public void push(Integer element) {
Stacm.addFirst(element);
}

public Integer pop() {
return Stack.removeFirst();
}

public Integer peek() {
return Stack.peekFirst();
}

public String toString() {
return Stack.toString();
}

public static void main(String[] args) {
IntegerStack stack = new IntegerStack();
for (int i = 1; i <=5; i++) {
stack.push(i);
}
System.out.println("After pushing 5 elements: " + stack);

int m = stack.pop();
System.out.println("Popped element = " + m);

System.out.println("After popping 1 element : " + stack);

int n = stack.peek();
System.out.println("Peeked element = " + n);

System.out.println("After peeking 1 element : " + stack);
}
}

3. Define a linked list
LinkedList<String> linkedlist = new LinkedList<String>(); // Linked list of String

4. Define a Queue
Queue<String> queue = new LinkedList<>();

5. Comparable interface

class Student implements Comparable<Student>{
int rollno;
String name;
int age;
Student(int rollno,String name,int age){
this.rollno=rollno;
this.name=name;
this.age=age;
}
  
public int compareTo(Student st){ // Compare function for student age
if(age==st.age)
return 0;
else if(age>st.age)
return 1;
else
return -1;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote