m1m2313
BAN USERimport java.util.*;
import java.io.*;
public class PrintAnagrams
{
String sorting(String s)
{
char str[]=new char[20];
int n=s.length();
str=s.toCharArray();
int i,j;char temp;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(str[i]>str[j])
{
temp=str[i];
str[i]=str[j];
str[j]=temp;
}
}
}
String t=new String(str);
return t;
}
public static void main(String args[]) throws IOException
{
PrintAnagrams pa=new PrintAnagrams();
String s,t,i;
String oldstr,newstr;
HashMap<String,String> hm=new HashMap<String,String>();
FileReader fr=new FileReader("file.txt");
BufferedReader br=new BufferedReader(fr);
int c=1;
while((s=br.readLine())!=null)
{
t=pa.sorting(s);
if(hm.containsKey(t))
{
oldstr=hm.get(t);
newstr=oldstr+" "+s;
hm.put(t,newstr);
}
else
hm.put(t,s);
}
Set<Map.Entry<String,String>> set=hm.entrySet();
for(Map.Entry<String,String> me : set)
System.out.println(me.getValue());
}
}
This code finds preorder successor of the node p in a bst with root t .
}
- m1m2313 July 08, 2012