@ankit
Can you explain your code????????
On Tue, Jul 26, 2011 at 12:29 PM, ankit sambyal <[email protected]>wrote:
> @coder :Got my mistake. There is a slight change in the checkmin function.
> Actually I was returning the modified value of i and j. Following is the
> correct code :
>
>
> #include<iostream>
> using namespace std;
>
>
> int checkmin(char arr[],int size,int i,int j)
> {
> int k=0,*m=i,n=j*;
>
>
> while(arr[i]==arr[j] && k<size)
> {
> i=(i+1)%size;
> j=(j+1)%size;
> k++;
> }
> if(k==size)
> *return m; * //Strings at i and j are both
> same. You can return either index
>
> else if(arr[i]<arr[j]) //String starting at index i is
> less than string starting at index j
> * return m;*
> else //String starting at index j is
> less than string starting at index i
> *return n;*
> }
>
>
> int getFirstIndexInLex(char arr[],int size)
> {
> int minindex=0,i;
> for(i=1;i<size;i++)
> {
> if(arr[i] < arr[minindex])
> minindex=i;
> else if(arr[i]==arr[minindex])
> minindex=checkmin(arr,size,minindex,i);
> }
> return minindex;
> }
>
>
>
> int main()
> {
> cout<<getFirstIndexInLex("ABCDEAABCCDA",12);
> }
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
Thank You
Rajeev Kumar
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.