-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserlist.java
50 lines (45 loc) · 1013 Bytes
/
userlist.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
//user made linked list
import java.io.*;
import java.util.*;
class Node
{
Node next;
int data;
Node(int d)
{
data=d;
next=null;
}
}
public class UserList
{
Node head;
public void insert(int element)
{
Node n = new Node(element);
n.next=head;
head=n;
}
public void print()
{
Node no = head;
while(no!=null)
{
System.out.println("Linked List : "+ no.data+" ");
no=no.next;
}
}
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter how many elements u wanna insert : ");
int n = Integer.parseInt(br.readLine());
UserList ul = new UserList();
for(int i =0; i<n; i++)
{
int num = Integer.parseInt(br.readLine());
ul.insert(num);
}
ul.print();
}
}