J
Jimakos Bilakis
Hi everyone!
I want to create a function that it will take as parameters a table
(float), an integer (the number of Table's rows) and it will re-arrange
the elements in the table from the smallest value to the biggest one. I
know it's very simple but something is missing from my code... Untill
now i manage to create something like this:
1. void FunctionReArrange (float Table[], int TableRows)
2. {
3. float Help1 = 0;
4. float Help2 = 0;
5.
6. if (TableRows <= 1)
7. cout<<"Nothing's gonna happen!";
8. else
9. {
10. for (int a=0; a<=TableRows-1; a++)
11. {
12. for (int b=1; b<=TableRows-1; b++)
13. {
14. if (Table[a] > Table)
15. {
16. Help1 = Table[a];
17. Help2 = Table;
18.
19. Table[a] = Help2;
20. Table = Help1;
21. }
22. }
23. }
24. }
25.}
I tried this one with the table (in main):
float myTable[4] = {1.17, 1.37, 1.00, 1.31};
FunctionReArrange (myTable, 4);
When i compile and run the code, i get results similar to these:
myTable = {1.00, 1.37, 1.17, 1.31} which of course aren't the right
results! (1.00, 1.17, 1.31, 1.37) It's very clear that i cannot see a
detail... The error is somewhere in lines 14 - 20.
When it comes to line 12 for the 1st time it has
Table[a] = Table[0] = 1.17 and Table = Table[1] = 1.37. It's ok so
it takes the next element.
Then it has
Table[a] = Table[0] = 1.17 and Table = Table[2] = 1.00.
So it goes for the change. After that i have myTable[4] = {1.00, 1.37,
1.17, 1.31}!
Here is the "spot" where i want to write something so i can return the
whole procedure from the beginning, couse my code continues like no
change happened.(It continues the check like i had declared the table
myTable with elements {1.00, 1.37, 1.17, 1.31} from the start - it
doesn't recognise that the elements have changed and that it has to
beggin the procudure from the beginning)!
Can anyone help me?
Thanks in advance!
I want to create a function that it will take as parameters a table
(float), an integer (the number of Table's rows) and it will re-arrange
the elements in the table from the smallest value to the biggest one. I
know it's very simple but something is missing from my code... Untill
now i manage to create something like this:
1. void FunctionReArrange (float Table[], int TableRows)
2. {
3. float Help1 = 0;
4. float Help2 = 0;
5.
6. if (TableRows <= 1)
7. cout<<"Nothing's gonna happen!";
8. else
9. {
10. for (int a=0; a<=TableRows-1; a++)
11. {
12. for (int b=1; b<=TableRows-1; b++)
13. {
14. if (Table[a] > Table)
15. {
16. Help1 = Table[a];
17. Help2 = Table;
18.
19. Table[a] = Help2;
20. Table = Help1;
21. }
22. }
23. }
24. }
25.}
I tried this one with the table (in main):
float myTable[4] = {1.17, 1.37, 1.00, 1.31};
FunctionReArrange (myTable, 4);
When i compile and run the code, i get results similar to these:
myTable = {1.00, 1.37, 1.17, 1.31} which of course aren't the right
results! (1.00, 1.17, 1.31, 1.37) It's very clear that i cannot see a
detail... The error is somewhere in lines 14 - 20.
When it comes to line 12 for the 1st time it has
Table[a] = Table[0] = 1.17 and Table = Table[1] = 1.37. It's ok so
it takes the next element.
Then it has
Table[a] = Table[0] = 1.17 and Table = Table[2] = 1.00.
So it goes for the change. After that i have myTable[4] = {1.00, 1.37,
1.17, 1.31}!
Here is the "spot" where i want to write something so i can return the
whole procedure from the beginning, couse my code continues like no
change happened.(It continues the check like i had declared the table
myTable with elements {1.00, 1.37, 1.17, 1.31} from the start - it
doesn't recognise that the elements have changed and that it has to
beggin the procudure from the beginning)!
Can anyone help me?
Thanks in advance!