-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_deletion3.java
More file actions
52 lines (48 loc) · 1.02 KB
/
list_deletion3.java
File metadata and controls
52 lines (48 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//program to complete the whole list
public class LinkedList
{
Node head;
static class Node
{
Node next;
int data;
Node(int d)
{
data=d;
next=null;
}
}
//function to delete the whole list
public void delete()
{
head = null; //garbage collection happens on its own in java
}
public void insert(int element)
{
Node n = new Node(element);
n.next=head;
head=n;
}
public void print()
{
Node no=head;
while(no!=null)
{
System.out.print(no.data+" ");
no=no.next;
}
}
public static void main(String args[])
{
LinkedList dl = new LinkedList();
dl.insert(10);
dl.insert(20);
dl.insert(30);
dl.insert(94);
System.out.print("Initially the list is : ");
dl.print();
dl.delete();
System.out.println("Deleted list is: ");
dl.print();
}
}