In Java write a menu driven program that implements the foll

In Java write a menu driven program that implements the following linked list operations :

INSERT (at the beginning)

INSERT_ALPHA (in alphabetical order)

DELETE (Identify by contents, i.e. \"John\", not #3)

COUNT

CLEAR

Solution

sorting........................................

class LinkedList
{
Node head;

// link list
class Node
{
int data;
Node next;
Node(int d) {data = d; next = null; }
}

//function for sorted list
  
void sortedIns(Node new_node)
{
Node current;

if (head == null || head.data >= new_node.data)
{
new_node.next = head;
head = new_node;
}
else {


current = head;

while (current.next != null &&
current.next.data < new_node.data)
current = current.next;

new_node.next = current.next;
current.next = new_node;
}
}


// function for the creation of node
Node newNode(int data)
{
Node x = new Node(data);
return x;
}



public static void main(String args[])
{
LinkedList llist = new LinkedList();
Node new_node;
new_node = llist.newNode(5);
llist.sortedIns(new_node);
new_node = llist.newNode(10);
llist.sortedIns(new_node);
new_node = llist.newNode(7);
llist.sortedIns(new_node);
new_node = llist.newNode(3);
llist.sortedIns(new_node);
new_node = llist.newNode(1);
llist.sortedIns(new_node);
new_node = llist.newNode(9);
llist.sortedIns(new_node);
System.out.println(\"Created Linked List\");
llist.printList();
}
}

if u have to delete an item

temp=head;

arr=head;

for(i=1;i<=link_list_len;i++)

{

arr++;

while(node->data==data1)

{

x=node;

arr=node->nxt;

}

}

In Java write a menu driven program that implements the following linked list operations : INSERT (at the beginning) INSERT_ALPHA (in alphabetical order) DELETE
In Java write a menu driven program that implements the following linked list operations : INSERT (at the beginning) INSERT_ALPHA (in alphabetical order) DELETE

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site