// DoublyLinkedList.java
public class DoublyLinkedList {
// inner class DNode to represent a node in doubly linked list
class DNode
{
private String name; // data
private DNode prev; // pointer to previous node
private DNode next; // pointer to next node
// constructor that create a node with given name and pointers to prev and next is null
public DNode(String name)
{
this.name = name;
}
}
private DNode head; // pointing to start of the list
private DNode tail; // pointing to end of the list
// constructor that creates an empty list
public DoublyLinkedList()
{
head = null;
tail = null;
}
// method to insert name in list in sorted order
public void insert(String name)
{
DNode node = new DNode(name);
if(head == null) // if empty list, insert as head node
{
head = node;
tail = node;
}else if(head.name.toLowerCase().compareTo(name.toLowerCase()) > 0) // if data in head > name then update head
{
node.next = head;
head.prev = node;
head = node;
}else if(name.toLowerCase().compareTo(tail.name.toLowerCase()) > 0) // if data in tail < name then update tail
{
tail.next = node;
node.prev = tail;
tail = node;
}else
{
// insert in middle
DNode curr = head;
// loop to insert the node in the middle of the list
while(curr != null)
{
if(curr.name.toLowerCase().compareTo(name.toLowerCase()) > 0)
{
curr.prev.next = node;
node.prev = curr.prev;
node.next = curr;
curr.prev = node;
return ;
}
curr = curr.next;
}
}
}
// method to remove a name from the list
public void remove(String name)
{
// if list is empty, do nothing
if(head != null)
{
if(head.name.toLowerCase().compareTo(name.toLowerCase()) == 0) // if head is the node to be deleted update head
{
head = head.next;
if(head == null)
tail = null;
else
head.prev = null;
}else
{
// delete the node in the middle or end
DNode curr = head;
while(curr != null)
{
if(curr.name.toLowerCase().compareTo(name.toLowerCase()) == 0)
{
curr.prev.next = curr.next;
if(curr.next != null)
{
curr.next.prev = curr.prev;
}else
{
tail = curr.prev;
}
return;
}
curr = curr.next;
}
}
}
}
// method to display the list in ascending order
public void display()
{
if(head == null)
System.out.println("List is empty");
else
{
DNode curr = head;
while(curr != null)
{
System.out.println(curr.name);
curr = curr.next;
}
}
}
// method to display the list in descending order
public void displayReverse()
{
if(head == null)
System.out.println("List is empty");
else
{
DNode curr = tail;
while(curr != null)
{
System.out.println(curr.name);
curr = curr.prev;
}
}
}
}
//end of DoublyLinkedList.java
// DoublyLinkedListDriver.java : Java program to test the DoublyLinkedList class
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class DoublyLinkedListDriver {
public static void main(String[] args) throws FileNotFoundException {
// test the class
Scanner scan = new Scanner(new File("input.txt")); // open the file input.txt
DoublyLinkedList list = new DoublyLinkedList();
String name;
while(scan.hasNext())
{
name = scan.next();
if(name.equalsIgnoreCase("delete"))
{
name = scan.next();
list.remove(name);
}else
list.insert(name);
}
scan.close();
System.out.println("List in ascending order : ");
list.display();
System.out.println("List in descending order : ");
list.displayReverse();
}
}
//end of DoublyLinkedListDriver.java
Output:
Input file:

Output:

Help in JAVA please Write a program that reads a list of students (first names only)...
implement a doubly-linked list in C. Each node in the linked list should contain a string, a pointer to the previous node (or NULL), and a pointer to the next node (or NULL). The nodes should be sorted by their strings. struct node_t { char* str; struct node_t* prev; struct node_t* next; } To maintain the doubly-linked list, you should keep a pointer to the head node of the list (or NULL if the list is empty), and a pointer...
Write a c/c++ program to read a list of students from a file and create a list. The program should use a linked list for implementation. Each node in the linked list should have the student’s name, a pointer to the next student, and a pointer to a linked list of scores. There may be up to four scores for each student.
C++ Data Structure Write a program to read a list of students from a file and create a list. The program should use a linked list for implementation. Each node in the linked list should have the student’s name, a pointer to the next student, and a pointer to a linked list of scores. There may be up to four scores for each student.
c++ only Program 2: Linked List Class For this problem, let us take the linked list we wrote in a functional manner in a previous assignment and convert it into a Linked List class. For extra practice with pointers we’ll expand its functionality and make it a doubly linked list with the ability to traverse in both directions. Since the list is doubly linked, each node will have the following structure: struct Node { int number; Node * nextNode;...
C++ Program 1. Read data for names and weights for 15 people. 2. Your program will build a list for the data maintained in ascending order based on both name and weight via a doubly linked list. 3. This dll will use one pointer to keep weights in sorted order, and use the other link to keep names on sorted order. 4. You need to build the list as you go maintaining this ordering, so at any time a print...
C++ Program 1. Read data for names and weights for 15 people. 2. Your program will build a list for the data maintained in ascending order based on both name and weight via a doubly linked list. 3. This dll will use one pointer to keep weights in sorted order, and use the other link to keep names on sorted order. 4. You need to build the list as you go maintaining this ordering, so at any time a print...
Please use C++
CS3358 Insert and delete a node Programming Project 2: The linked list - Reference: chapter 18: Create an array of 15 student records that should not be sorted Create a liked list of 15 student record nodes. Each node is a node of one student record from the above unsorted array. The list of student records should be sorted by student ID. (Insert function without sort function to create a linked list.) (If you insert correctly, the...
Write a java program implementing the Linked list. It should be on an small office who has 5 employees. The program ask the user for ID, First name, Last name and what field the work in(eg: accounting, programmer, HR etc). Each employee (with all the information of that paticular employee) should be placed in one node in the program. The program should repeat and ask the user for all 5 employees information. Also when you display the Linked list it...
Python program
- Write a Python program, in a file called sortList.py, which, given a list of names, sorts the names into alphabetical order. Use a one dimensional array to hold the list of names. To do the sorting use a simple sorting algorithm that repeatedly takes an element from the unsorted list and puts it in alphabetical order within the same list. Initially the entire list is unsorted. As each element is placed in alphabetical order, the elements in...
I need this in C++. This is all
one question
Program 2: Linked List Class For this problem, let us take the linked list we wrote in a functional manner in a previous assignment and convert it into a Linked List class. For extra practice with pointers we'll expand its functionality and make it a doubly linked list with the ability to traverse in both directions. Since the list is doubly linked, each node will have the following structure: struct...