-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedList.java
More file actions
47 lines (39 loc) · 656 Bytes
/
Copy pathLinkedList.java
File metadata and controls
47 lines (39 loc) · 656 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
36
37
38
39
40
41
42
43
44
45
46
47
package practice1;
public class LinkedList {
public Node head;
public LinkedList()
{
head=null;
}
public boolean isEmpty()
{
return(head==null);
}
public void printList()
{
Node itr=head;
while(itr!=null)
{
System.out.println(itr.data);
itr=itr.next;
}
}
public void addToHead(int num)
{
Node newnode=new Node(num);
newnode.next=head;
head=newnode;
}
public static Node reverse1(Node head)
{
if(head==null||head.next==null) return head;
Node newhead=reverse1(head.next);
head.next.next=head;
head.next=null;
return(newhead);
}
public void reverse()
{
this.head=reverse1(this.head);
}
}