Reverse each individual word in sentence?
void reversestr(char* str, char* strend)
{ char tmp; while(strend>str) { tmp = *strend; *strend = *str; *str = tmp; str++; strend--; } return; } void reverseSen(char *sentence) { char *wordstart=sentence, *wordstop=sentence; char *pSend=sentence,*pSstart =sentence ; int size=0; while(*pSend != '\0'){ pSend++; size++; } pSend--; // reverese stentence reversestr(pSstart,pSend); while(wordstop < pSend) { //find the word while((*wordstop!='\0')&&(*wordstop!=' ')) wordstop++; wordstop--; //reverese the word reversestr(wordstart,wordstop); wordstart = wordstop +2; wordstop = wordstart; } } Find out if a string is a palindrome?
bool Palindrome(char *str)
{ Find a repeated integer in array of size n?int DuplicatedNumber(int *a, int size) return founddup ? a[i] : -1; // return the duplicated value or -1 if not found Giving Two Strings, Find out whether they are Anagrams(made up of same chars) or not?
If(strlen(Str1)!=strlen(Str2)) return FALSE;
sort both Str1,Str2. If(str1==str2) return TRUE; else return FALSE; Game of Russian roulette!!You are tied to a chair and can,t get up.Here is the gun , six chambers all empty. Now I put two bullets in the gun and I put these bullets in the adjecent chambers. I close the barrel and spin it. I put the gun to your head and pull the trigger. Clik and the slot was empty. Now before we start the interview I want to pull the trigger one more time , which one do you prefer , that I spon the barrel first or that I just pull the trigger ? X being a bullet, _ being and empty chamber. The gun rotates from 1 to 6, and the bullets are in adjacent chambers. The setup: _ X X _ _ _ The interviewer just got a blank, so the current position must be 1,4,5, or 6. If it’s 1, the next one is a bullet. If it’s 4-6, the next one is empty. So if the interviewer just fires again, you have a 1/4 chance of getting shot. If, on the other hand, the interviewer spins again, you’re back to the initial 2/6 or 1/3 chance of getting shot. I’ll take the 1/4 chance, myself. WAP to reverse a linked list?void reverse(NODE **head) { } Recusive way call with original = list, parent = NULL Node* reverselinkedlist(Node* original, Node*parent) if(original == NULL) } return reverse; }
Subscribe to:
Posts (Atom)
|
Categories
Blog ArchiveRent A Coder |