bbarodia
BAN USER
public class sortInPlace {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int arr[] = {1,3,5,6,2,4,7};
sortArray(arr);
}
public static void sortArray(int []a)
{
int endOfFirstArray = 0,prevNum = -1;
if(a.length < 2)
{
return ;
}
if(a.length == 2)
{
if ( a[0] > a[1]) {
int temp = a[1];
a[1] = a[0];
a[0] = temp;
}
}
prevNum = 0;
for (int i = 1; i < a.length ; i++ )
{
if ( a[prevNum] > a[i])
{
break;
}
prevNum++;
}
int ptr2 = a.length -1 ,ptr1 = prevNum;
for (; ptr2 > ptr1 ; )
{
if (a[ptr2] > a[ptr1])
{
ptr2--;
}
else
{
int temp = a[ptr2];
a[ptr2] = a[ptr1];
a[ptr1] = temp;
int tempPtr2 = ptr2;
for (int j = tempPtr2 -1 ; j >=0 ; j--)
{
if (a[tempPtr2] < a[j] )
{
temp = a[tempPtr2];
a[tempPtr2] = a[j];
a[j] = temp;
}
tempPtr2--;
}
}
}
for (int i = 0 ; i < a.length ; i++)
{
System.out.println (a[i]);
}
}
}
divide by 8 ..store in bytes_copied
mod by 8 ...store in leftover_bits
perform normal memcpy using bytes at dest_address
new_dest_address = dest_address + bytes_copied ;
new_src_Address = src_address + bytes_copied ;
uint8 mask = (1 << (leftover_bits + 1) - 1;
uint8 maskComplement = ~(mask);
new_dest_address = (*new_src_address & mask ) | (*new_dest_address & maskComplement);
nope...thats not the way to do it...........for more ppl this doesnt scale well.
we have to do event based programming here.
Have a priority Q.
There are 3 types of events, person coming ,person leaving and the moment we need to examine.
push all these into a priority Q sorted according to time
remove each element until you get to the moment you want a count of.
hashmap is the way to go here.... the underlying implementation of hashmap could be an array.
for add:
We hash the value to a number between [0..N], and add it at that position in the array. We need to describe collision management techniques.
if ur size increases than N, you will be reshashing the entire DS into
for delete:
same as above, rehash if size drops to quarter the capacity.
get :
is almost naturally constant for hash
getRandom :
choose a key randomly between 0 and currentcapacity. if the key has some value then return it, else hash again. you could choose to perform some optimization here w.r.t the currentSize on the number of retries.
List <List<Integer> getCombinations (int num)
{
List <List<Integer>> allCombinations = new ArrayList<Integer>();
int val = num;
int i = 1;
while (val > 0)
{
List<Integers> temp1 = new ArrayList<Integer>();
temp1.add (i++);
List<List<Integers> tempList = getCombinations (val --);
int j = 0;
for (List<Integer> subList : tempList)
{
temp1.addAll(subList);
}
allCombinations.add(temp1);
}
return allCombinations;
}
}
if modifying is not an option, use stack
- bbarodia May 14, 2013