This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyStack<Item> | |
{ | |
private Node first = null; | |
private class Node | |
{ | |
Item item; | |
Node next; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyArrayStack<Item> | |
{ | |
private Item[] s; | |
private int index; | |
public MyArrayStack(int capacity) { | |
s = (Item[]) new Object[capacity]; | |
index = 0; | |
} | |
public boolean isEmpty() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyVarSizeArrayStack<Item> | |
{ | |
private Item[] s; | |
private int index; | |
public MyVarSizeArrayStack() { | |
s = (Item[]) new Object[1]; | |
index = 0; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Question195 | |
{ | |
public static class Result | |
{ | |
private int hits; | |
private int pseudohits; | |
} | |
public static Result estimate(String guess, String solution) { | |
Result res = new Result(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Question194 | |
{ | |
public static int getMax(int a, int b) { | |
int c = a - b; | |
int k = ( c >> 31) & 0x1; | |
return a - k * c; | |
} | |
public static void main(String[] args) { | |
int a = 5; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Question192 | |
{ | |
public static int numZeros(int num) { | |
int count = 0; | |
if (num < 0) { | |
return -1; | |
} | |
for(int i = 5; num / i > 0; i *= 5) { | |
count += num / i; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Java is not working ??? pass by value?? | |
public class Question191 | |
{ | |
public static void swap(int a, int b) { | |
a = a ^ b; | |
b = a ^ b; | |
a = a ^ b; | |
} | |
public static void main(String[] args) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Question197 | |
{ | |
public static int maxsum(int[] a) { | |
int maxsum = 0; | |
int sum = 0; | |
for (int i = 0; i < a.length; i++) { | |
sum += a[i]; | |
if( maxsum < sum) { | |
maxsum = sum; | |
} else if (sum < 0) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Hashtable; | |
public class Question198 | |
{ | |
public static Hashtable<String, Integer> createHashtable(String[] book) { | |
Hashtable<String, Integer> table = new Hashtable<String, Integer>(); | |
for(int i = 0; i < book.length; i++) { | |
book[i] = book[i].toLowerCase(); | |
if(book[i].trim() != "") { | |
if( !table.containsKey(book[i])) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Hashtable; | |
import java.util.Arrays; | |
public class Question1911 | |
{ | |
//hashtable implementation, needs to figure out the repeated printout pair and collision | |
public static void findpair(int sum, int[] a) { | |
Hashtable<Integer, Integer> table = new Hashtable<Integer, Integer>(); | |
for(int i = 0; i < a.length; i++) { | |
if( !table.containsKey(a[i])) { |
OlderNewer