forked from codehouseindia/Java-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.java
More file actions
52 lines (52 loc) · 847 Bytes
/
Copy pathmain.java
File metadata and controls
52 lines (52 loc) · 847 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
49
50
51
52
class linkedList
{
private class node
{
int data;
node next;
}
node start;
linkedList()
{
start=null;
}
public void insertAtBeg(int item)
{
node n=new node();
n.data=item;
if(start==null)
{
start=n;
n.next=null;
}
else
{
n.next=start;
start=n;
}
}
public void display()
{
node temp=new node();
temp=start;
while(temp.next!=null)
{
System.out.print(temp.data+" ");
temp=temp.next;
}
System.out.println(temp.data);
}
}
class Main
{
public static void main(String... argv)
{
linkedList l=new linkedList();
l.insertAtBeg(10);
l.insertAtBeg(20);
l.insertAtBeg(30);
l.insertAtBeg(40);
l.insertAtBeg(50);
l.display();
}
}