# algorithm help

• 02-19-2003
the Wookie
algorithm help
hey guys i need your help, this has been driving me nuts

i have 5 boxes, stacked on top of the each other, numbering 1 -> 5.

1
2 <--focus position
3
4
5

the location of box #2 is the position on which the user's focus lies. now to the function i pass which box i want to be in the focus position, so everything will shift up or down so that box is in the focus position, ie:

focus box = 4

3
4 <--focus position
5
1
2

or

focus box = 1

5
1 <-- focus position
2
3
4

i dont know how to do the controlling loop for this..any ideas? code isnt needed pseudocode is good for me..its actually in java..but java/c++ synactically close enough for me..i can convert it over. my brain isnt working now so i probably need a break, but any ideas would be great. ha that kinda rhymed..
• 02-19-2003
RoD
maybe a for loop for the size of the vector array?
• 02-19-2003
abrege
try this

Code:

```#include <iostream> #include <conio.h> using namespace std; void push(int numbers[5]) {         int temp = numbers[0];         for(int i = 0; i < 5; i ++)         {                 if(i < 4)                         numbers[i] = numbers[i + 1];                 else                         numbers[i] = temp;         } } int main() {         int numbers[5], focus;         for(int i = 0; i < 5; i ++)                 numbers[i] = i;         while(1)         {                 system("cls");                 for(int i = 0; i < 5; i ++)                         cout << numbers[i] << endl;                 cout << "Focus: ";                 cin >> focus;                 while(numbers[1] != focus)                         push(numbers);         }         return 0; }```
• 02-19-2003
the Wookie
ah cool..thanks, that gave me an idea
how about sorting it in the proper order? because the boxes are an array, and its like a JPanel with a bunch of stuff from each "number" on it..yeah..but that gave me an idea, ill tryit at work tomorrow. thanks
• 02-19-2003
abrege
Pausing between each transition should give it the panel effect?

Code:

```#include <iostream> #include <conio.h> #include <windows.h> using namespace std; inline void print(int numbers[10]) {         for(int i = 0; i < 10; i ++)                 cout << numbers[i] << ' '; } void push(int numbers[5]) {         system("cls");         int temp = numbers[0];         for(int i = 0; i < 10; i ++)         {                 if(i < 9)                         numbers[i] = numbers[i + 1];                 else                         numbers[i] = temp;         }         print(numbers);         Sleep(500); } int main() {         int numbers[5], focus;         for(int i = 0; i < 10; i ++)                 numbers[i] = i;         print(numbers);         while(1)         {                 cout << "\nFocus: ";                 cin >> focus;                 while(numbers[1] != focus)                         push(numbers);         }         return 0; }```
• 02-19-2003
the Wookie
no i meant whats being sorted like this are "panels", its a gui app in java