-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkList2.java
More file actions
61 lines (55 loc) · 1.44 KB
/
linkList2.java
File metadata and controls
61 lines (55 loc) · 1.44 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
53
54
55
56
57
58
59
60
61
package datastructure;
public class b {
public static class Node{
int data;
Node next;
}
static Node insertAtf(Node head,int data){
Node temp=new Node();
temp.data=data;
temp.next=head;
return temp;
}
static Node insertintoAtlast(Node head,int data){
Node temp=new Node();
temp.data=data;
temp.next=null;
Node temp2=head;
while(temp2!=null){
temp2=temp2.next;
}
temp2.next=temp;
return head;
}
public static void t(Node first){
Node temp=first;
while(temp!=null){
System.out.print(temp.data+" ");
temp=temp.next;
}
}
public static void main(String[] args) {
Node first=new Node();
first.data=100;
first.next=null;
Node second=new Node();
second.data=200;
second.next=null;
first.next=second;
Node third=new Node();
third.data=300;
third.next=null;
second.next=third;
Node fourth=new Node();
fourth.data=400;
fourth.next=null;
third.next=fourth;
t(first);
System.out.println();
Node head=insertAtf(first,34);
t(head);
System.out.println();
head=insertintoAtlast(head,34);
t(head);
}
}