Skip to content

Commit e40e27d

Browse files
committedOct 26, 2018
mnb LinkedList-java algo first commit
1 parent 08860d7 commit e40e27d

File tree

6 files changed

+101
-0
lines changed

6 files changed

+101
-0
lines changed
 

‎LinkedList/LinkList.class

1.27 KB
Binary file not shown.

‎LinkedList/LinkList.java

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
public class LinkList{
2+
private Node head;
3+
4+
public void LinkList(){
5+
head=null;
6+
}
7+
8+
public void insert(int i){
9+
Node newNode = new Node(i);
10+
newNode.next = head;
11+
head = newNode;
12+
13+
System.out.println("New Node Inserted : "+i);
14+
}
15+
16+
public Node find(int key){
17+
int i=1;
18+
Node current = null;
19+
20+
current = head;
21+
22+
while(current != null && i != key){
23+
current = current.next;
24+
i++;
25+
}
26+
27+
return current;
28+
29+
}
30+
31+
public void delete(int key){
32+
Node current = null;
33+
Node previous = null;
34+
35+
current = head;
36+
previous = head;
37+
38+
int i = 1;
39+
40+
while(current.next != null && i != key){
41+
42+
previous = current;
43+
current = current.next;
44+
i++;
45+
}
46+
if(current==head){
47+
head = head.next;
48+
}else{
49+
previous.next = current.next;
50+
}
51+
System.out.println("Item Deleted");
52+
}
53+
54+
public void display(){
55+
Node current;
56+
57+
current = head;
58+
59+
while(current != null){
60+
System.out.println("Node : "+ current.item);
61+
current = current.next;
62+
}
63+
}
64+
65+
66+
}

‎LinkedList/Node.class

448 Bytes
Binary file not shown.

‎LinkedList/Node.java

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class Node{
2+
3+
public int item;
4+
public Node next;
5+
6+
public Node(int i){
7+
this.item = i;
8+
this.next = null;
9+
}
10+
11+
public void displayNode(){
12+
System.out.println(item);
13+
}
14+
}

‎LinkedList/Run.class

610 Bytes
Binary file not shown.

‎LinkedList/Run.java

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
public class Run{
2+
3+
public static void main(String args[]){
4+
5+
LinkList mylist = new LinkList();
6+
7+
mylist.insert(10);
8+
mylist.insert(20);
9+
mylist.insert(30);
10+
mylist.display();
11+
12+
Node retur = mylist.find(2);
13+
System.out.println(retur.item);
14+
15+
mylist.delete(2);
16+
mylist.display();
17+
18+
mylist.delete(2);
19+
mylist.display();
20+
}
21+
}

0 commit comments

Comments
 (0)
Please sign in to comment.