Posts

Showing posts with the label Solution

[Solution]Level order traversal

void Levelorder(struct node* p) {     stack<struct node*> s;     queue<struct node*> q;      struct node* temp;     s.push(p);     do     {         while(!s.empty())         {             temp = s.top();             cout<<temp->data<<endl;             s.pop();               if(temp->left)                 q.push(temp->left);              if(temp->right)           ...

Rotation of an integer array

#include using namespace std ; int findRotation ( int arr [ ] , int low, int high ) {     int mid ;     while ( arr [ low ] > arr [ high ] )     {      mid = low + ( high - low ) / 2 ;       if ( arr [ mid ] > arr [ high ] )      low = mid + 1 ;       else      high = mid ;       }       return low ; } int main ( ) {   //this is the array rotated by 2 positions   int arr [ ] = { 5 , 6 , 1 , 2 , 3 } ;   cout << "rotation of array is" << findRotation ( arr, 0 , 4 ) ;   return 0 ; }