|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
shift an array? |
Posted: Wed Feb 13, 2008 6:21 pm |
|
|
Hi,
how to shift values in an array, in a circular loop ?
example:
array[10] = {0,1,2,3,4,5,6,7,8,9}
shift + 1 the values (no values are lost)
to become:
array[10] = {1,2,3,4,5,6,7,8,9,0}
thank you
bye bye |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
|
Posted: Wed Feb 13, 2008 11:04 pm |
|
|
hi hi,
Sounds like a homework. Here's a tip: you need one additional variable to prevent the loss of data.
bye bye _________________ Read the label, before opening a can of worms. |
|
|
D-Kens
Joined: 09 May 2005 Posts: 35 Location: Toulouse (France)
|
|
Posted: Thu Feb 14, 2008 2:50 am |
|
|
Something like that ?
Code: | j=array[9] ;
for (i=0 ; i<9 ; i++) { array[9-i]=array[9-i-1] ; }
array[0]=j ; |
Edit :oops, sorry, I was sleeping ! I shifted the array in the wrong direction... But sure you can do the change by yourself. |
|
|
Guest
|
|
Posted: Thu Feb 14, 2008 8:07 am |
|
|
Hi kender,
I'm just trying to learn some basics !
I have found a function named memmove ,, is this function more efficient ?
ccsinfo.com/forum/viewtopic.php?t=27272&highlight=memmove
But i think that is trying to do a FIFO (first in, first out)
If you know this function could you show me a simple example please
thank you
simon |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Thu Feb 14, 2008 12:23 pm |
|
|
Anonymous wrote: | Hi kender,
I'm just trying to learn some basics !
I have found a function named memmove ,, is this function more efficient ?
ccsinfo.com/forum/viewtopic.php?t=27272&highlight=memmove
But i think that is trying to do a FIFO (first in, first out)
If you know this function could you show me a simple example please
thank you
simon |
For a small array you cant beat simple direct byte moves.
Code: |
j=array[0] ;
array[0]=array[1];
array[1]=array[2];
array[2]=array[3];
array[3]=array[4];
array[4]=array[5];
array[5]=array[6];
array[6]=array[7];
array[7]=array[7];
array[8]=array[9];
array[9]=j;
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|