https://github.com/imsaiful/shilpa
https://github.com/imsaiful/shilpa
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/imsaiful/shilpa
- Owner: imsaiful
- Created: 2017-11-11T18:15:22.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-11T21:35:39.000Z (over 8 years ago)
- Last Synced: 2025-03-21T16:59:04.677Z (about 1 year ago)
- Language: Java
- Size: 6.84 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# shilpa
Menu driven for the TreeSet
```
import java.util.*;
class Shilpa
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
TreeSet ts = new TreeSet();
System.out.println("Enter the initial Capacity of TreeSet");
int n=in.nextInt();
for(int i=1;i<=n;i++)
{
System.out.println("Enter the "+i+" element ");
int x=in.nextInt();
ts.add(x);
}
boolean condition=true;
while(condition)
{
System.out.println("Enter your choise");
System.out.println("1. View Elements \n2. Insert Element\n3. Delete Elements\n4. Search Element\n5. Exit");
int c=in.nextInt();
if(c==1)
{
Iterator itr=ts.iterator();
while(itr.hasNext()){
System.out.print(itr.next()+" ");
}
}
else if(c==2)
{
System.out.println("Enter the element");
int x=in.nextInt();
ts.add(x);
System.out.println("Element is inserted Successfully");
}
else if(c==3)
{
System.out.println("Enter the element to delete");
int x=in.nextInt();
if(ts.remove(x))
{
System.out.println("Element deleted");
}
else
{
System.out.println("Element not exist");
}
}
else if(c==4)
{
System.out.println("Enter the element to search");
int x=in.nextInt();
int y=ts.headSet(x).size()+1;
if(y<=ts.size())
{
System.out.println("Elements found at position "+y);
}
else
{
System.out.println("Elements not found");
}
}
else if(c==5)
{
System.exit(0);
}
else
{
System.out.println("Please enter the correct option");
}
}
}
}
```