can u plz explain dis code?
On Wed, Jul 27, 2011 at 12:37 AM, coder coder
<[email protected]>wrote:
> the answer should be 6 correct me if i am getting the question wrong
>
>
> #include<iostream>
> using namespace std;
>
>
> int checkmin(char arr[],int size,int i,int j)
> {
> int k=0;
>
> while(arr[i]==arr[j] && k<size)
> {
> i=(i+1)%size;
> j=(j+1)%size;
> k++;
> }
> if(k==size)
>
> return i; //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 i;
> else //String starting at index j is
> less than string starting at index i
> return j;
> }
>
>
> 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);
> system("pause");
>
> }
>
>
> --
> 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.
>
--
Aditi Garg
Undergraduate Student
Electronics & Communication Divison
NETAJI SUBHAS INSTITUTE OF TECHNOLOGY
Sector 3, Dwarka
New Delhi
9718388816
--
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.