-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircularLinkedList.java
More file actions
120 lines (80 loc) · 2.48 KB
/
CircularLinkedList.java
File metadata and controls
120 lines (80 loc) · 2.48 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Dell
*/
import java.util.*;
import java.io.*;
class Node2{
static Node next;
static Node prev;
static int data;
}
public class CircularLinkedList {
public static Node head;
public static Node tail;
public static void insert(int i){
if(head == null){
Node first = new Node();
first.data = i;
first.next = head;
head = first;
tail = first;
}
else{
Node later = new Node();
later.data = i;
later.next = head;
//tail = head;
head = later;
Node2.next = head;
Node2.prev = tail;
//System.out.print( Node2.next.data + "->");
}
}
public static void print(){
Node temp = Node2.next;
while(temp != null){
System.out.print(temp.data + "->");
temp = temp.next;
}
System.out.println("\nhead of the circular linked list is :: " + Node2.next.data);
System.out.println("tail of the circular linked list is :: " +Node2.prev.data);
}
public static void delete(int i){
System.out.println("performing a delete ");
Node temp = Node2.next;
if(i == temp.data){
head = temp.next;
Node2.next = head;
}
else{
while(temp.next.data != i){
temp = temp.next;
}
if(temp.next == Node2.prev){
Node2.prev = temp;
}
temp.next = temp.next.next;
}
}
public static void search(int i){}
public static void main(String[] args){
head = null;
tail = null;
insert(10);
insert(25);
insert(35);
insert(45);
insert(55);
print();
delete(55);
print();
delete(10);
print();
}
}