Newbie
BAN USERpublic class test {
public static void main(String[] args) {
String temp = "RajeshNaiduG";
System.out.println(FindMax(temp));
}
private static String FindMax(String str)
{
int j=6,i=0;
int n=str.length();
while(j<str.length())
{
String temp=str.substring(i+1,j);
String temp1= str.substring(j+1);
String temp3=str.substring(0,i+1);
str = temp3+str.charAt(j)+temp+temp1;
i=i+2;
j++;
}
return str;
}
}
1 ArrayList<Point> current_path = new ArrayList<Point>();
2 public static boolean getPaths(int x, int y) {
3 Point p = new Point(x, y);
4 current_path.add(p);
5 if (N == x && N == y) return true;
6 boolean success = false;
7 if (x <N && is_free(x + 1, y)) {
8 success = getPaths(x + 1, y);
9 }
10 if (!success && y <N && is_free(x, y + 1)) {
11 success = getPaths(x, y + 1);
12 }
13 if (!success) {
14 current_path.remove(p);
15 }
16 return success;
17 }
1. Create a Max Heap with the first k points using the distance factor..
2. For each remaining point, insert it in the Max Heap and then delete the max value from the heap.
3. The heap now contains the min k points.
4. This algorithm is O(n log m), where m is the number of points we are looking for.
@Araynium...u need to make changes to ur code to support cases 1,2,3...and r u sure whether u'll get correct in-order successors for all nodes..according to ur code i see some leaf nodes get their parent or someother node as successors which should be just null..
- Newbie January 06, 2011guys..here is a good solution and fair one.I copied frm id = 3747687
void printOuterTree(Node root){
if(root != null){
System.out.println(root.element);
printOuterTree(root.left,1,1);
printOuterTree(root.right,0,0);
}
}
void printOuterTree(Node root,int urFlag, int parentFlag){
if(root == null)
return;
if(root.left == null && root.right == null)
System.out.println(root.element);
else{
if(urFlag==1){//do a preorder for left subtree
if(urFlag == parentFlag)
System.out.println(root.element);
printOuterTree(root.left,1,urFlag);
printOuterTree(root.right,0,urFlag);
}
else{//do a post order for right sub tree
printOuterTree(root.left,1,urFlag);
printOuterTree(root.right,0,urFlag);
if(urFlag == parentFlag)
System.out.println(root.element);
}
}
}
wht if size of rows and column are different
- Newbie January 10, 2011