Posts

Showing posts from March 5, 2014

Hash Table in java

import java.util.*;
import java.io.*;
class ab
{
public static void main(String args[])throws Exception
{
Hashtable s =new Hashtable();

System.out.println(s);
s.put("1","a");
s.put("2","b");
s.put("3","c");
System.out.println(s);
System.out.println(s.get("0"));
System.out.println(s.get("1"));
System.out.println("Size of table is : "+s.size());
s.clear();
System.out.println("Size of table is : "+s.size());
}
}

Stack in java

import java.util.*;
import java.io.*;
class a
{
public static void main(String args[])throws Exception
{
Stack s =new Stack();
System.out.println("Empty= "+s.empty());

s.push("1");
s.push("2");
s.push("3");
System.out.println(s);
System.out.println(s.search("0"));
System.out.println(s.search("1"));
System.out.println(s.search("2"));
s.pop();
System.out.println(s);
System.out.println(s.peek());
}
}