pantjeevan98
BAN USER
Comments (3)
Reputation -10
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
-2
of 2 vote
time complexity o(n2)
- pantjeevan98 July 01, 2015Comment hidden because of low score. Click to expand.
0
of 0 vote
import java.util.*;
public class Qus {
public static void main(String[] args) {
TreeSet set=new TreeSet();
set.add(new Csv("Alice",30));
set.add(new Csv("Bob",17));
set.add(new Csv("Clyde",49));
Iterator it= set.iterator();
while(it.hasNext())
{
Object ob=it.next();
System.out.println(ob);
}
}
}
class Csv implements Comparable
{
String name;
int age;
public Csv(String name,int age)
{
this.name=name;
this.age=age;
}
@Override
public int compareTo(Object o) {
if(o instanceof Csv)
{
Csv v=(Csv)o;
return this.age-v.age;
}
return 0;
}
public String toString()
{
return name+"\t"+age;
}
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
import java.util.*;
- pantjeevan98 August 03, 2015public class Count {
public static void main(String[] args) {
String str1 = "wwwwrrrrxxxde";
char ch[] = str1.toCharArray();
int l = ch.length;
int c = 1;
HashSet set = new LinkedHashSet();
HashMap map = new LinkedHashMap();
for (int i = 0; i < l; i++) {
char ch2 = ch[i];
boolean b = set.add(ch2);
if (b == false) {
c++;
map.put(ch2, c);
} else {
c = 1;
map.put(ch2, null);
}
}
List list = new ArrayList();
Set set1 = map.entrySet();
Iterator it = set1.iterator();
while (it.hasNext()) {
Object ob = it.next();
Map.Entry entry = (Map.Entry) ob;
Object ob1 = entry.getKey();
Object ob2 = entry.getValue();
list.add(ob1);
if (ob2 != null) {
list.add(ob2);
}
}
for(int i=0;i<list.size();i++)
{
System.out.println(list.get(i));
}
}
}