# Thread: Help with a simple problem that eludes me

1. ## Help with a simple problem that eludes me

i have a table
int tab1[25]
i need to organize the values in the table from smallest to largest(there are no numbers repeated) , BUT if the value is -1, then these have to go to the end of all other numbers
and example of the table before the organization would be
{4,7,2,9,5,10,-1,-1,-1,-1,-1,-1,-1,-1.....-1}
after the organization
{2,4,5,7,9,10,-1,-1,-1......-1}

Code:
```void organizer(int tab1[3][25])
{
int a,b,c;
int tabhelper[25];
for(a=0;a<3;a++)
{
for(b=0;b<25;b++)
{
tab1[a][b]=tabhelper[b];

}
for(b=0;b<25;b++)
{
int d;
if(tabhelper[b]>tabhelper[b+1])
{
d =tabhelper[b];
tabhelper[b]=tabhelper[b+1]
tabhelper[b+1]=d;
}
}

}

}```
ive been trying to do this for about 1 hour, but i always have some mistake or it just doesnt work, and i dont have much time to lose cause this is a reallly really small part of a project i have to do.
thank you in advanced

2. First of all why you are having a 2D array if you want to just sorting

3. Put it another way: sort the list of numbers in ascending order, with the proviso that -1 is treated as greater than any other number.

So, you can write out your sort normally, then test. You will end up with the -1s in front, but after that you just need to change the comparison to make it such that -1 is treated as greater than any other number.

4. You haven't initialized tabhelper array, so "tab1[a][b]=tabhelper[b];" will be put garbage values in the tab1 array.

5. woops sorry
i realize i did a big mistake in the first lines of code
it should be tabhelper[b]=tab1[a][b]; not tab1[a][b]=tabhelper[b];

6. i wrote the first part of the code wrong, its supposed to be tabhelper[b]=tab1[a][b]; not tab1[a][b]=tabhelper[b];
and i need to organize the 3 "sub" arrays of the double array table

7. you have to use any sorting algorithm. And take a counter which will take care of -1 and at the end concatenate all the -1 in to the array at end of it.

Popular pages Recent additions