-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircularll.java
More file actions
48 lines (46 loc) · 801 Bytes
/
Copy pathCircularll.java
File metadata and controls
48 lines (46 loc) · 801 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
48
import java.util.Scanner;
class Circularll {
node head;
public void insert(int data)
{
node n=new node();
n.data=data;
if(head==null)
{
head=n;
n.next=head;
}
else
{
node temp=head;
while(temp.next!=head)
{
temp=temp.next;
}
temp.next=n;
n.next=head;
}
}
void display()
{
node temp=head;
while(temp.next!=head)
{
System.out.println(temp.data);
temp=temp.next;
}
System.out.println(temp.data);
System.out.println(temp.next.data);
}
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
Circularll l=new Circularll();
int d=s.nextInt();
for(int i=0;i<d;i++)
{
int a=s.nextInt();
l.insert(a);
}
l.display();
}
}