forked from Anuj-3107/HACKTOBER2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinklist.java
More file actions
51 lines (49 loc) · 1.12 KB
/
Copy pathlinklist.java
File metadata and controls
51 lines (49 loc) · 1.12 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
import java.util.*;
class node{
int data;
node next;
node(int d){
data = d;
next=null;
}
}
class linklist{
node head = null;
static linklist insertbegining(linklist list,int data){
node newnode=new node(data);
if(list.head==null){
list.head=newnode;
}
else{
newnode.next=list.head;
list.head=newnode;
}
return list;
}
static void printinglist(linklist list){
node temp;
temp=list.head;
while(temp!=null){
System.out.print(temp.data+" ");
temp=temp.next;
}
}
public static void main(String[] args) {
int d;
Scanner sc=new Scanner(System.in);
linklist list=new linklist();
System.out.println("enter element data *******enter 0 to exit ");
while(true){
System.out.println("enter the element");
d=sc.nextInt();
if(d==0){
break;
}
else{
insertbegining(list,d);
}
}
printinglist(list);
sc.close();
}
}