-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueuelinkedlist.java
98 lines (92 loc) · 1.8 KB
/
queuelinkedlist.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
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
package datastructures;
import java.util.Scanner;
public class queuelinkedlist {
static node start=null;
static node temp=null;
public static void main(String[] args) {
// TODO Auto-generated method stub
linkedlist l=new linkedlist();
Scanner sc=new Scanner(System.in);
while(true)
{
System.out.println("1. Insert");
System.out.println("2. Delete");
System.out.println("3. Traverse");
System.out.println("Enter Choice");
int c=sc.nextInt();
switch(c)
{
case 1:
{
System.out.println("Enter number to enter:");
int n=sc.nextInt();
insert(n);
break;
}
case 2:
{
delete();
break;
}
case 3:
{
traverse();
break;
}
default:
{
System.out.println("Wrong choice");
}
}
System.out.println("Do you wanna continue 1. to continue");
int choice=sc.nextInt();
if(choice!=1)
return;
else
continue;
}
}
static void insert(int i)
{
node newnode=new node();
newnode.info=i;
newnode.link=null;
if(start==null)
{
start=newnode;
temp=newnode;
return;
}
temp.link=newnode;
temp=temp.link;
//start=newnode;
}
static void delete()
{
if(start==null)
{
System.out.println("Empty");
}
else if(start==temp)
{
start=null;
temp=null;
}
else
{
node ptr=start;
start=start.link;
System.out.println("Node from front"+ptr.info);
}
}
static void traverse()
{
node ptr=null;
ptr=start;
while(ptr!=null)
{
System.out.println(ptr.info);
ptr=ptr.link;
}
}
}