C Puzzles

yet another place for C puzzles

Friday, March 19, 2010

 

Finding the Nth-node-from-the-end of a linked list.

answer in my mind:

1. travel the linked list for n times
(if you hit null in between, return null)
2. Then travel the linked list till end
(remember to increment the n-node pointer along with traversal)

 

one linked list meet another linked list

Linked List B meet Linked List A at node J. find J

linked list A. heada->x->....->J->......->z->null
linked list B headb->y->....->J

 

sorted array right shfted

A sorted array . for eg: 2,3,6,8,11,23,56,89
It is right shifted unknown times eg: 23,56,89,2,3,6,8,11
now search an element in the array... say eg:56.
(no linear search allowed.)


answer in my mind:
1. first find the largest element by log(n)
2. now remove the first part or last part depends on search element.
3. now log(n) search for the item.

Monday, March 15, 2010

 

queues with two stacks

implement queue with two stacks


answer link

 

Big Endian or Little Endian

a c-program to find the endians of a processor?

answer:

unsigned int i = 0xabcdefgh;

unsigned char *pc = (unsigned char *) &i;

if (*pc == 0xgh) {
/* little endian */
} else {
/* big endian */
}

Archives

July 2005   August 2005   October 2005   December 2005   March 2006   June 2006   July 2006   December 2006   February 2007   June 2007   March 2010   May 2010  

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]