Reverse a linked list iteratively: struct list * reverse (struct list *l) { struct list *curr = l, *next, *temp =NULL; while (curr!=NULL) { next = curr->nxt; curr->nxt = temp; temp = curr; curr = next; } return temp; } Recursive : (struct list *)recursive_reverse(struct list *ptr) { if ((ptr == NULL)&&(ptr->next == NULL)) return ptr; struct list *temp = reverse(ptr->next); temp->next = ptr; return ptr; } Find number of 1s in a number: function iterativecount (unsigned int n) begin int count=0; while (n) begin count += n & 0x1 ; n >>= 1; end return count; end function sparsecount (unsigned int n) begin int count=0; while (n) begin count++; n &= (n-1); end return count ; end Notes ===== 1. Insertion sort good for already sorted list. 2. Heap sort - best case, avg case, worst case is O(nlogn). 3. Its always a fight between no. of movements and no. of comparisions. 4. realloc() - used to reallocate space can free memory and reallocate. Array of 1 - 1000 distinct numbers in array of size of 1001. Only one is repeated. Find out which? Soln1: Use auxilary space of 1000 and copy each in its respective location. soln2: Just freaking add all no.s in array and substract from 1000. http://www-ccs.ucsd.edu/c/string.html Q: "How would you find out if a machine's stack grows up or down in memory?" (my answer): Instantiate a local variable. Call another function with a local. Look at the address of that function and then compare. If the function's local is higher, the stack grows away from address location 0; if the function's local is lower, the stack grows towards address location 0. (If they're the same, you did something wrong!) Implement itoa using sprintf ============================ itoa(int i, char *str, int n) { sprintf(str, "%d", i); }