Professional Documents
Culture Documents
Reg no : FA22-BAI-031
LAB : DS
SUBMITTED TO : MAAM SAIDA RUBAB
/*
* To change this license header, choose License Headers in Project Properties.
*/
package javaapplication92;
class Node {
int data;
Node next;
this.data = data;
this.next = null;
class LinkedList {
public LinkedList() {
this.head = null;
newNode.next = head;
head = newNode;
}
int count = 1;
current = current.next;
count++;
if (current == null) {
return;
newNode.next = current.next;
current.next = newNode;
if (nodeNumber == 1) {
insertAtBeginning(data);
return;
}
Node newNode = new Node(data);
int count = 1;
current = current.next;
count++;
if (current == null) {
return;
newNode.next = current.next;
current.next = newNode;
current = current.next;
if (current == null) {
newNode.next = current.next;
current.next = newNode;
if (head == null) {
System.out.println("List is empty.");
return;
if (head.data == targetData) {
insertAtBeginning(data);
return;
current = current.next;
if (current.next == null) {
return;
}
newNode.next = current.next;
current.next = newNode;
current = current.next;
System.out.println();
myList.insertAtBeginning(1);
myList.insertAtBeginning(2);
myList.insertAtBeginning(3);
myList.insertAtBeginning(4);
myList.insertAtBeginning(5);
System.out.println("Original List:");
myList. SHOWDATA();
myList.insertAfterNodeNumber(3, 6);
myList.insertBeforeNodeNumber(4, 7);
myList.insertAfterData(5, 8);
myList.insertBeforeData(2, 9);
System.out.println("Modified List:");
myList. SHOWDATA();