Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #161658

Re: Does anybody have any idea that why the output is not the sorted array and how should edit the code and why the output is trash

From David Brown <david.brown@hesbynett.no>
Newsgroups comp.lang.c
Subject Re: Does anybody have any idea that why the output is not the sorted array and how should edit the code and why the output is trash
Date 2021-07-05 08:10 +0200
Organization A noiseless patient Spider
Message-ID <sbu7ph$9li$1@dont-email.me> (permalink)
References <142675bd-7993-49b5-9b68-40864f26003an@googlegroups.com> <87tulack51.fsf@bsb.me.uk> <sbt9bc$ckk$1@gioia.aioe.org>

Show all headers | View raw


On 04/07/2021 23:31, Manfred wrote:
> On 7/4/2021 2:56 PM, Ben Bacarisse wrote:
>> hamid daniali <hamiddaniaali@gmail.com> writes:
>>
> [...]
>>
>> Your code layout is mighty odd.  Many Google messed it up on posting...
>>
> 
> Definitely odd layout, which might be source of confusion for the OP in
> the first place.
> [...]
> 
>>
>>>     for(i=0;i<size-1;i++)
>>>     for(j=1;j<size;j++)
>>>     if (*(p+j+1)<*(p+j))
>>
>> I'd write p[j+1] and p[j] here.  But note that p[0] is never looked at
>> and (as has already been pointed out) when j == size-1, p[j+1] is out of
>> bounds.
>>
>>>     swap ((p+j+1),(p+j));}
>>
>> I fond the extra () slightly distracting.  If you want to keep a symmetry
>> with the p[j+1] notation you can write &p[j+1] for p+j+1.
>>
> 
> The intention seems to be a basic O(N^2) algorithm (with mistakes, which
> I won't do a rewrite for because this sounds like a homework assignment).
> Hint (nonetheless): the outer 'for' loop iterates on 'i', but 'i' is
> never used. This might be more visible if the code had been properly
> indented.

Second hint - always enable plenty of warnings on your compiler!  A good
compiler can give lots of help (such as telling you about unused
variables) if you let it.

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Does anybody have any idea that why the output is not the sorted array and how should edit the code and why the output is trash hamid daniali <hamiddaniaali@gmail.com> - 2021-07-04 03:28 -0700
  Re: Does anybody have any idea that why the output is not the sorted array and how should edit the code and why the output is trash WeAllWant ToBeHappy <weallwanttobehappy@gmail.com> - 2021-07-04 03:56 -0700
  Re: Does anybody have any idea that why the output is not the sorted array and how should edit the code and why the output is trash Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-07-04 13:56 +0100
    Re: Does anybody have any idea that why the output is not the sorted array and how should edit the code and why the output is trash Manfred <noname@add.invalid> - 2021-07-04 23:31 +0200
      Re: Does anybody have any idea that why the output is not the sorted array and how should edit the code and why the output is trash David Brown <david.brown@hesbynett.no> - 2021-07-05 08:10 +0200
  Re: Does anybody have any idea that why the output is not the sorted array and how should edit the code and why the output is trash Vir Campestris <vir.campestris@invalid.invalid> - 2021-07-04 21:27 +0100
  Re: Does anybody have any idea that why the output is not the sorted array and how should edit the code and why the output is trash Real Troll <real.troll@trolls.com> - 2021-07-05 18:45 +0000

csiph-web