Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvinmaniar123 authored Oct 16, 2018
1 parent f184752 commit c5f8f8d
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions singly.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import java.util.*;
class singly
{
Node head=null;
Node end=null;
class Node{
int data;
Node link;
Node(int d){
data =d;
link=null;
}
}
public static void main(String ar[]){
singly s=new singly();
Scanner st=new Scanner(System.in);
int choice,in;
while(true){
System.out.println("\n"+"1.Insert at Front"+"\n"+"2.Delete at Front"+"\n"+"3.Insert at End"+"\n"+"4.Delete at End"+"\n"+"5.Delete element"+"\n"+"6.Exit");
choice=st.nextInt();
switch(choice){
case 1:System.out.println("Enter element to insert:");
in=st.nextInt();
s.insertFront(in);
s.display();
break;
// case 2:s.deleteFront();
// s.display();
// break;
// case 3:System.out.println("Enter element to insert:");
// in=st.nextInt();
// s.insertEnd(in);
// s.display();
// break;
// case 4:s.deleteEnd();
// s.display();
// break;
// case 5:System.out.println("Enter pos:");
// in=st.nextInt();
// s.deletePos(in);
// s.display();
// break;
// case 6:System.out.println("Enter pos:");
// in=st.nextInt();
// s.search(in);
// s.display();
// break;
default:System.out.println("Incorrect Input.");
break;
}
}
}
public void insertFront(int info){
Node new_node=new Node(info);
if(head==null){
new_node.link=null;
head=new_node;

}
else{
new_node.link=head;
head=new_node;
}
}
public void insertEnd(int info){
Node new_node=new new_node();
if(new_node==null){
System.out.print("NO space");
}
else{
new_node.data=info;
new_node.link=null;
}

}
public void display(){
if(head==null){
System.out.println("No elements are present");

}
else{
Node temp=head;
while(temp!=null){
System.out.print(temp.data+"->");
temp=temp.link;

}
}
}

}

0 comments on commit c5f8f8d

Please sign in to comment.