Skip to content

Commit

Permalink
Added some more algorithm questions
Browse files Browse the repository at this point in the history
  • Loading branch information
rakeshcusat committed Nov 26, 2011
1 parent 0dd82a3 commit 8422b9a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
24 changes: 24 additions & 0 deletions Algorithm/CPP/find_no_in_array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <iostream>
#include <stack>

using namespace std;

void find_number(int array[],int size,int num){

for(int index=0;index<size;)
{
if(array[index] == num){
cout<<"Found the number at index = "<<index<<endl;
return;
}
index += num-array[index];
}
cout<<"Couldn't find the number "<<endl;
}
int main(int argc, char **argv){

int myarray[]={3,4,5,4,3,2,3,4,5,6,7,8,9,10,9};
find_number(myarray, sizeof(myarray)/sizeof(int),7);

return 0;
}
5 changes: 4 additions & 1 deletion Algorithm/ReadMe.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ combination of characters
CPP/char_combination.cpp

Reverse stack.
CPP/reverse_stack.cpp
CPP/reverse_stack.cpp

Given an array such that every number differ from its adjacent number by at max 1. Find a number in this array efficiently.
CPP/find_no_in_array.cpp

0 comments on commit 8422b9a

Please sign in to comment.