Thread: algorithm help

  1. #1
    i want wookie cookies the Wookie's Avatar
    Join Date
    Oct 2002
    Posts
    455

    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..
    Last edited by the Wookie; 02-19-2003 at 05:19 PM.

  2. #2
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    maybe a for loop for the size of the vector array?

  3. #3
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369
    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;
    }
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

  4. #4
    i want wookie cookies the Wookie's Avatar
    Join Date
    Oct 2002
    Posts
    455
    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

  5. #5
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369
    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;
    }
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

  6. #6
    i want wookie cookies the Wookie's Avatar
    Join Date
    Oct 2002
    Posts
    455
    no i meant whats being sorted like this are "panels", its a gui app in java

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Implement of a Fast Time Series Evaluation Algorithm
    By BiGreat in forum C Programming
    Replies: 7
    Last Post: 12-04-2007, 02:30 AM
  2. Replies: 4
    Last Post: 12-10-2006, 07:08 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM