-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLinked.java
69 lines (57 loc) · 1.46 KB
/
Linked.java
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
62
63
64
65
66
67
68
69
class ll{
public Node head;
class Node{
private int data;
private Node next;
}
public void insert(int data,Node ptr){
Node newNode =new Node();
newNode.data=data;
newNode.next=null;
if(ptr==null){
if(head==null)
head=newNode;
else{
Node temp=head;
head=newNode;
head.next=temp;
}
}
else{
Node temp=ptr.next;
ptr.next=newNode;
newNode.next=temp;
}
}
public void display(){
Node temp=head;
while(temp!=null){
System.out.println(temp.data);
temp=temp.next;
}
}
public void inserter(ll l2){
Node h= l2.head;
int i=1;
Node temp =head;
while(temp!=null){
if(i%2==1){
Node ptr=temp;
insert(h.data,ptr);
h=h.next;
}
i++;
temp=temp.next;
}
}
}
public class Linked{
static public void main(String[]args){
ll l1= new ll();
ll l2= new ll();
l1.insert(5, null);
l2.insert(5,null);
l1.inserter(l2);
l1.display();
}
}