-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedlist3.java
More file actions
35 lines (31 loc) · 784 Bytes
/
Copy pathlinkedlist3.java
File metadata and controls
35 lines (31 loc) · 784 Bytes
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
class linkedlist3{
class node{
int data;
node next;
node(int data){
this.data=data;
this.next=null;
}
}
static node head = null;
void insertbeg(int data){
if(head==null){
head = new node(data);
}else{
node newnode = new node(data);
newnode.next = head;
head= newnode;
}
}
public static void main(String args[]){
linkedlist3 obj = new linkedlist3();
obj.insertbeg(2);
obj.insertbeg(4);
obj.insertbeg(3);
node current = head;
while(current != null){
System.out.println(current.data);
current= current.next;
}
}
}