♣♣♣ WRITE A PROGRAM TO CREATE OBJECT FOR TREESET AND
STACK AND USE ALL METHODS. ♣♣♣
import java.io.*;
import java.util.*;
class pro8
{
public
static void main(String args[]) throws IOException
{
InputStreamReader
a =new InputStreamReader(System.in);
BufferedReader
b =new BufferedReader(a);
TreeSet
ts=new TreeSet();
System.out.print("\nEnter
the total no. of Items : ");
int n=Integer.parseInt(b.readLine());
String str=null;
for(int
cnt=1;cnt<=n;cnt++)
{
System.out.print("\nEnter
the "+cnt+" character : ");
str=b.readLine();
ts.add(str);
}
System.out.println("\n\tThe
Item on the tree are : \t"+ts);
System.out.println("\n\tThe
first item on the tree is : \t"+ts.first());
System.out.println("\n\tThe
last item on the tree is : \t"+ts.last());
System.out.println("\n\tTotal
no. of item on the tree are : \t"+ts.size());
System.out.print("\nEnter
the element you want to delete : ");
String del=b.readLine();
ts.remove(del);
System.out.println("\n\tThe
Item on the tree are : \t"+ts);
}
}
OUTPUT :-
Enter
the total no. of Items :4
Enter the 1 character : we
Enter the 2 character : are
Enter the 3 character : LogicCafe
Enter the 4 character : Team
The Item on the tree are : [are,
LogicCafe , Team,
we]
The first item on the tree is : are
The last item on the tree is : we
Total no. of item on the tree
are : 4
Enter the element you want to
delete : we
The Item on the tree are : [are,
LogicCafe , Team]
No comments:
Post a Comment