Question

In: Computer Science

plz use doubly linked list. java Q1) Create a program that do the following: 1. Asks...

plz use doubly linked list. java

Q1) Create a program that do the following:
1. Asks the user to enter n marks for n students, read the marks and the names and store them in a double linked list.

2. Write a method to find the largest mark and print the name of the student having that mark

3. Write a method to print the content of the list (name, mark)

4. Write a method to search the list for a given mark and prints the result
6. Insert 2 new students to the list (print the list before and after the insertion)

7. Delete any students with the first letter "D" in his name, (print the list before and after the deletion)
Submit .java files only.

Solutions

Expert Solution

package learning;
import java.util.*;

class Student{
        public String name;
        public int marks;
        
        Student(String name,int marks){
                this.name = name;
                this.marks = marks;
        }
}

class node{
        public Student S;
        node next;
        node prev;
        
        node(Student S){
                this.S = S;
                next=null;
                prev=null;
        }
}

class DLL{
        node head=null;
        node tail=null;
        
        void insert(String name,int marks) {
                if(head == null) {
                        head = new node(new Student(name,marks));
                        tail = head;
                }else {
                        tail.next =  new node(new Student(name,marks));
                        
                        tail.next.prev = tail;
                        
                        tail = tail.next;
                        
                }
        }

        void largest() {
                node temp = head;
                Student Max = new Student("dummy",-1000);
                while(temp!=null) {
                        if(temp.S.marks > Max.marks) {
                                Max = temp.S;
                        }
                        
                        temp = temp.next;
                }
                System.out.println("Student with Largest Marks: ");
                System.out.println(Max.name);
                System.out.println(Max.marks);
                System.out.println();
        }
        
        void printList() {
                node temp = head;
        
                while(temp!=null) {
                        System.out.println(temp.S.name);
                        System.out.println(temp.S.marks);
                        temp = temp.next;
                }
        }
        
        void printMarks(int m) {
                node temp = head;
                
                while(temp!=null) {
                        
                        if(temp.S.marks == m) {
                                System.out.println(temp.S.name);
                                System.out.println(temp.S.marks);
                                System.out.println();
                        }
                        
                        temp = temp.next;
                }
        }
        
        void delete(char c) {
                node temp = head;
                
                while(temp!=null) {
                        
                        if(temp.S.name.charAt(0) == c) {
                                temp.prev.next = temp.next;
                                temp.next.prev = temp.prev;
                        }
                        
                        temp = temp.next;
                }
        }
        
        
}

class Main {
        public static void main(String[] args) {
                        
                        Scanner input = new Scanner(System.in);
                        DLL D = new DLL();
                        
                        System.out.print("Enter the number of students to insert:");

                        int n = Integer.parseInt(input.nextLine());
                        
                        for(int i=0;i<n;++i) {
                                System.out.print("Enter the name of the student:");
                                String name = input.nextLine();
                                System.out.print("Enter the marks of the student:");
                                int marks = Integer.parseInt(input.nextLine());
                                D.insert(name, marks);
                                
                        }
                        System.out.println();
                        
                        
                        
                        D.printList();
                        
                        System.out.println();
                        
                        System.out.print("Enter the marks to search for:");
                        int marks = Integer.parseInt(input.nextLine());
                        
                        D.printMarks(marks);
                        
                        System.out.println();
                        
                        D.largest();
                        
                        System.out.print("Enter the first Character of student name to delete:");
                        
                        char c =input.nextLine().charAt(0);
                        
                        D.delete(c);
                        
                        System.out.print("List after deleting students with first character "+ c + ":\n");
                        
                        D.printList();
                        
        }
}
        

OUTPUT:


Related Solutions

Can you make this singular linked list to doubly linked list Create a Doubly Linked List....
Can you make this singular linked list to doubly linked list Create a Doubly Linked List. Use this to create a Sorted Linked List, Use this to create a prioritized list by use. Bring to front those links recently queried. -----link.h------ #ifndef LINK_H #define LINK_H struct Link{ int data; Link *lnkNxt; }; #endif /* LINK_H */ ----main.cpp---- //System Level Libraries #include <iostream> //I/O Library using namespace std; //Libraries compiled under std #include"Link.h" //Global Constants - Science/Math Related //Conversions, Higher Dimensions...
TITLE Updating Accounts Using Doubly Linked List TOPICS Doubly Linked List DESCRIPTION General Write a program...
TITLE Updating Accounts Using Doubly Linked List TOPICS Doubly Linked List DESCRIPTION General Write a program that will update bank accounts stored in a master file using updates from a transaction file. The program will maintain accounts using a doubly linked list. The input data will consist of two text files: a master file and a transaction file. See data in Test section below.  The master file will contain only the current account data. For each account, it will contain account...
**JAVA** Create a Linked List and conduct the following operations. Portion of the program is given....
**JAVA** Create a Linked List and conduct the following operations. Portion of the program is given. The operations are: Add an “H” to the list Add an “I” to the list Add “100” to the list Print the content of the list and its size Add a “H” to the first place of the list Add a “R” to the last place of the list Get the element of position 3 and print it Get the last element and print...
A circular doubly-linked list .(a) In a circular doubly-linked list, there is no front or end;...
A circular doubly-linked list .(a) In a circular doubly-linked list, there is no front or end; the nodes form a full circle. Instead of keeping track of the node at the front, we keep track of a current node instead. Write a class for a circular doubly-linked list using the attached Job class as your node objects. It should have: • A private instance variable for the current node • A getCurrent() method that returns a reference to the current...
Given a doubly linked list in c++, how do I create a function that returns the...
Given a doubly linked list in c++, how do I create a function that returns the pointer to first node in the given pattern, For example, given mainList (a -> b -> c -> d) and sublist  (b -> c), our function should return a Node pointer that points to first node of the sublist in the mainList. If the pattern doesn't exist in the mainList, we should return a nullptr, there are multiple of the same sublist in the mainList,...
Given a doubly linked list in c++, how do I create a function that returns the...
Given a doubly linked list in c++, how do I create a function that returns the pointer to first node in the given pattern, For example, given mainList (a -> b -> c -> d) and sublist  (b -> c), our function should return a Node pointer that points to first node of the sublist in the mainList. If the pattern doesn't exist in the mainList, we should return a nullptr, there are multiple of the same sublist in the mainList,...
Create a generic Linked List that does NOT use the Java library linked list. Make sure...
Create a generic Linked List that does NOT use the Java library linked list. Make sure it contains or access a subclass named Node (also Generic). And has the methods: addFirst(), addLast(), add(), removeFirst(), removeLast() and getHead(). In a separate Java class provide a main that creates an instance of your LinkedList class that creates an instance of your LinkedList that contains String types. Add the five names (you pick them) to the list and then iterate through the list...
Exercise 1: Write a program in Java to manipulate a Singly Linked List: 1. Create Singly...
Exercise 1: Write a program in Java to manipulate a Singly Linked List: 1. Create Singly Linked List 2. Display the list 3. Count the number of nodes 4. Insert a new node at the beginning of a Singly Linked List. 5. Insert a new node at the end of a Singly Linked List 6. Insert a new node after the value 5 of Singly Linked List 7. Delete the node with value 6. 8. Search an existing element in...
Java program to implement circular linked list. NO COPY PASTE ANSWERS plz follow the given template......
Java program to implement circular linked list. NO COPY PASTE ANSWERS plz follow the given template... public class CircularLinkedList { private Node tail; private int size; public CircularLinkedList() { tail= null; size = 0; } public int size(){ return size; } public boolean isEmpty() { return size==0; } //if list is not empty return the first element public E first() { if (isEmpty()) return null; //code here return 0; } //if list not empty return last element public E last()...
Using Linked List, create a Java program that does the following without using LinkedList from the...
Using Linked List, create a Java program that does the following without using LinkedList from the Java Library. and please include methods for each function. Create a menu that contains the following options : 1. Add new node at the end of LL. ( as a METHOD ) 2. Add new node at the beginning of LL. ( as a METHOD ) 3. Delete a node from the end of LL. ( as a METHOD ) 4. Delete a node...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT