0% found this document useful (0 votes)
4 views3 pages

Practical File

Uploaded by

Karan Shelake
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Practical File

Uploaded by

Karan Shelake
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Insertion code

public class Linked_List {


static class node{
int data;
node next;
node(int value){
data=value;
next=null;
}
}
static node head;
static void printList(){
node p=head;
System.out.print("\n[");

while(p != null){
System.out.print(" " + p.data + "");
p=p.next;
}
System.out.print("]");
}
static void insertatbegin(int data){
node lk = new node(data);;
lk.next = head;
head=lk;
}
static void deleteatbegin(){
head=head.next;
}
public static void main(String args[]){
int k=0;
insertatbegin(12);
insertatbegin(22);
insertatbegin(30);
insertatbegin(44);
insertatbegin(50);
System.out.print("Linked List: ");
printList();
deleteatbegin();
System.out.print("\nLinked list after deletion: ");
printList();
}
}

Output:

Deletion code:

public class Linked_List {


static class node{
int data;
node next;
node(int value){
data=value;
next=null;
}
}
static node head;
static void printList(){
node p=head;
System.out.print("\n[");

while(p != null){
System.out.print(" " + p.data + "");
p=p.next;
}
System.out.print("]");
}
static void insertatbegin(int data){
node lk = new node(data);;
lk.next = head;
head=lk;
}
static void deleteatbegin(){
head=head.next;
}
public static void main(String args[]){
int k=0;
insertatbegin(12);
insertatbegin(22);
insertatbegin(30);
insertatbegin(44);
insertatbegin(50);
System.out.print("Linked List: ");
printList();
deleteatbegin();
System.out.print("\nLinked list after deletion: ");
printList();
}
}

Output:

You might also like