-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSLList.java
149 lines (88 loc) · 2.1 KB
/
SLList.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import java.io.*;
class snode
{
int info;
snode link;
snode()
{
info=0;
link=null;
}
snode(int x)
{
info=x;
link=null;
}
}
class SList
{
DataInputStream inp=new DataInputStream(System.in);
snode head;
int count;
SList()
{
head=null;
count=0;
}
snode getnode()throws IOException
{
System.out.println("enter the data :");
int val=Integer.parseInt(inp.readLine());
snode nn=new snode(val);
return nn;
}
void createnode()throws IOException
{
int ch;
snode nn;
snode last=null;
do
{
System.out.println("Do you want to create a node?(1-yes/2-no)");
ch=Integer.parseInt(inp.readLine());
if(ch==1)
{
nn=getnode();
count++;
if (head==null)
nn=head;
else
last.link=nn;
last=nn;
}
} while(ch==1);
}
void printlist()
{
snode temp;
temp=head;
if(head==null)
System.out.println("List is empty.....");
else
{
System.out.println("\nTotal number of nodes in the list is="+count);
System.out.println("the singly linked list is..........");
while(temp!=null)
{
System.out.print(temp.info+"-> ");
temp=temp.link;
}
System.out.println("null");
}
}
class SLList
{
public static void main(String args[])
{
SList sl=new SList();
try
{
sl.createnode();
sl.printnode();
}
catch(IOException e)
{
System.out.println("input output error"+e);
}
}
}