If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: Bubble Sort-question

If an array is defined as

Code:

int a[10];

What are the first and last element index of the array as used by c/c++?

All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

Re: Bubble Sort-question

Re: Bubble Sort-question

There is also an improvment you can make to your bubble-sort that will give a small performance improvement when the data is in near-sort order.

All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

Re: Bubble Sort-question

Originally Posted by mathmari

The first is a[0],the last a[9]...

So why for(i=0;i<10;i++) then and not for(i=0;i<=10;i++) ??

All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

Re: Bubble Sort-question

Re: Bubble Sort-question

Originally Posted by mathmari

Because there is no a[10]!!!!

All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/