-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode2.java
More file actions
48 lines (48 loc) · 1.06 KB
/
Node2.java
File metadata and controls
48 lines (48 loc) · 1.06 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
public class Node2
{
int item;Node2 object;
void add_beginning( int num)
{
Node2 temp=new Node2();
temp.item=num;
temp.object=null;
if(object==null)
object=temp;
else{
Node2 n=object;
while(n.object!=null)
n=n.object;
n.object=temp;
}
}
void newwhere(int x)
{
Node2 n=object;
Node2 p=null;Node2 y=new Node2();
int i=1;
while(n.object!=null)
{
p=n;
n=n.object;
if(i>=(x))
{
y.item=p.item;
p.item=n.item;
n.item=y.item;
}
++i;
}p.object=null;
}
void show()
{
Node2 temp=new Node2();
temp=object;
System.out.println("The Data in the Linked List:");
while(temp.object!=null)
{
System.out.print("|"+temp.item+"|->");
temp=temp.object;
}
System.out.println("|"+temp.item+"|");
}
}