# On C++ cocktail shaker

1. Feb 26, 2004

### franz32

help On C++, recursive function

Hello.

I need help... does anyone know /where can I get the code for the cocktail shaker algorithm for C++ in which it contains the simplest code?

How would I make a graphics sort out of the elementary sorting algorithms? Are there sources w/c show the codes for making graphsort?

Last edited: Feb 27, 2004
2. Feb 26, 2004

### dduardo

Staff Emeritus
Last edited by a moderator: Apr 20, 2017
3. Feb 27, 2004

### Guybrush Threepwood

oh, I see. now it has some connection with what I learned from college.....

4. Feb 27, 2004

### franz32

Thank you... now this time on recursive function

Oh, thanks for the shaker sort... some sources say it is called the bi-directional bubble sort.

The new problem: Write a recursive function with no local variables and no loops that will accept 2 parameters seed and size where...
seed denotes the first number to appear in the output screen
size - no of columns. (allows to display single digit numbers...)

Ex.1 seed: 3
size: 3

output:
3 4 5
6 7
8

ex2. seed: 7
size: 5

output:
7 8 9 0 1
2 3 4 5
6 7 8
9 0
1

I made a recursive function out of these: Try it. (Turbo C++)
# include <iostream.h>
# include <conio.h>
# include <stdlib.h>

int recur(int seed, int size);
int col(int seed, int size);
int main()
{
clrscr();
int seed, size;
cout << "input seed: ";
cin >> seed;
cout << "input no. of columns: ";
cin >> size;
col (seed, size);
getch();
return 0;
}

int col (int seed, int size)
{
if (size != 0)
{
recur (seed, size);
cout << "\n";
size -= 1;
seed = seed + size + 1;
if (seed > 10)
seed -= 10;
col (seed, size);
}
return 0;
}

int recur (int seed, int size)
{
if (size != 0)
{
if (seed == 10)
{
seed = 0;
cout << "0" << " ";
seed += 1;
recur (seed, size - 1);
}
else
{
cout << seed << " ";
seed += 1;
recur (seed, size - 1);
}
}
return 0;
}

That's one example I've made on my own... is there another way of showing a different way of creating recursive function following the restrictions above? I hope someone can show it to me...