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...
In JAVA: Create a circular doubly linked list. It need not be generic. Implement addToStart and...
In JAVA: Create a circular doubly linked list. It need not be generic. Implement addToStart and addToEnd methods, as well as printList method. Implement delete(Node n) method that deletes a node n, if n is in the linked list. Make no assumptions about n. Test your linked list.
Using Doubly Linked List, create a java code that does the following Without using LinkedList from...
Using Doubly Linked List, create a java code 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 operations : 1. Add new node to DLL. ( as a METHOD ) 2. Delete a node from DLL. ( as a METHOD ) 3. Show how many nodes in DLL. ( as a METHOD ) 4. Print all data in the DLL. ( as a METHOD...
Q1) Create a program that do the following: 1. Asks the user to enter n marks...
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...
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...
Write an efficient java program to implement an integer doubly linked list Dequeue which insertion and...
Write an efficient java program to implement an integer doubly linked list Dequeue which insertion and deletion can be than at either end. You have to write 6 methods: add front, delete front, add rear, delete rear, print forward (left to right) and print backward (right to left). After each addition or deletion dequeue elements are printed forward or backward respectively. Your main method should be as follow: public static void main(String args[]) { xxxxx dq = new xxxxx ();...
**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,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT