5
Contributors
6
Replies
14
Views
5 Years
Discussion Span
Last Post by klklklk
Featured Replies
  • 1

    [QUOTE=ddanbe;1547859]Why you want to do that? Just use the Sort method of the array.[/QUOTE] One word: Homework Read More

0
for (int pass = 1; pass <= wordsArray.Length; pass++)
    {
        for (int j = 0; j <= wordsArray.Length - 2; j++)
        {
           [B] if (wordsArray[j] > wordsArray[j + 1])[/B]    i find the error over this line.. .logical error i think please help me      
                {
                string Swap; 
                Swap = wordsArray[j];
                wordsArray[j] = wordsArray[j + 1];
                wordsArray[j + 1] = Swap;
            }
        }
    }

Edited by Reverend Jim: Fixed formatting

0

The string class has no overloaded > operator. Use a Compare method of the string class for that.
EDIT: You can only use == and != operators in an if statement when comparing strings.

Edited by ddanbe: n/a

0

Hi

string[] wordsArray = { "a", "bb", "ccc", "d", "ee", "f", "ggg" };
            for (int pass = 0; pass < wordsArray.Length; pass++)
            {
                for (int j = 0; j <= wordsArray.Length - 2; j++)
                {
                    if (wordsArray[j] > wordsArray[j + 1]) //when you come the last character of the array index [j+1] will throw an error - becuase its out of bounds!!
                    {
                        string Swap;
                        Swap = wordsArray[j];
                        wordsArray[j] = wordsArray[j + 1];
                        wordsArray[j + 1] = Swap;
                    }
                }
            }

What exactly would you like to do here?

1

Why you want to do that? Just use the Sort method of the array.

One word: Homework

Votes + Comments
Guess I was in outer space, thanks for bringing me back. :)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.