choi.bumyong
BAN USER
public class MergeArrays {
public static int[] merge(int[] a, int[] b) {
int length = a.length + b.length;
int[] c = new int[length];
int i=0, j=0, k=0;
while(k< c.length) {
if(i == a.length) {
c[k] = b[j++];
} else if(j == b.length) {
c[k] = a[i++];
} else if(a[i] < b[j]) {
c[k] = a[i++];
} else {
c[k] = b[j++];
}
++k;
}
return c;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] a = {1,3,7,9,11};
int[] b = {2,4,6,7,22};
int[] c = merge(a,b);
for(int num : c) {
System.out.print(num + " ");
}
}
}
ignore the main class.. not sure what happened.
- choi.bumyong October 25, 2011<pre lang="" line="1" title="CodeMonkey62146" class="run-this">/* The class name doesn't have to be Main, as long as the class is not public. */
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
java.io.BufferedReader r = new java.io.BufferedReader (new java.io.InputStreamReader (System.in));
String s;
while (!(s=r.readLine()).startsWith("42")) System.out.println(s);
}
}
class ReverseStack {
// a simple recursive method that pops from the bottom of the stack
// and push that number
public void reverse(Stack<Integer> stack) {
if (stack.isEmpty())
return;
int bottom = popFromBottom(stack);
reverse(stack);
stack.push(bottom);
}
// recursive method that gets the number in the bottom of the stack
private Integer popFromBottom(Stack<Integer> stack) {
Integer oldValue = stack.pop();
// if the stack is empty after a pop operation, we know that
// we just got the number in the bottom of the stack and we can
// return this value
if (stack.isEmpty()) {
return oldValue;
}
// if this is not the number in the bottom of the stack, then keep going
Integer value = popFromBottom(stack);
// we need to put everything back into the stack except the number int he bottom
stack.push(oldValue);
return value;
}
}</pre><pre title="CodeMonkey62146" input="yes">
</pre>
Reprickyjwerner, Area Sales Manager at Accolite software
I am Ricky, I live in Houston USA, I am working as a distribution manager in Total Serve company. I ...
Reppaynealiciam, Apple Phone Number available 24/7 for our Customers at Adap.tv
Hello I am Sarah Cote, and I live in Missouri, USA. Last year, Web trailblazer. Passionate entrepreneur. Subtly charming bacon ...
Repjoankelly306, Site Manager at EFI
Hi, I am Joan from Fairbanks, in USA. I have been a Food Product Manager in a Food Barn Company ...
Repmerrittmonique9, Android Engineer at AMD
I am Monique and working in high court from last 20 years.Handel many cases in my career.Build and ...
Repannarrathjen, Employee at 247quickbookshelp
Hello, My name is Anna and I am a medical records technician with 2 years of experience and achievements. I ...
I agree! O(n*n) is the only solution I get.
- choi.bumyong October 25, 2011