View Full Version : On C++... cocktail shaker
franz32
Feb26-04, 09:41 AM
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?
dduardo
Feb26-04, 01:21 PM
For those that don't know, the cocktail shaker sort is more commonly known as bubble sort.
franz32, try this site out::
http://linux.wku.edu/~lamonml/algor/sort/sort.html
Guybrush Threepwood
Feb27-04, 02:00 AM
Originally posted by dduardo
[B]For those that don't know, the cocktail shaker sort is more commonly known as bubble sort.
oh, I see. now it has some connection with what I learned from college.....
franz32
Feb27-04, 02:21 AM
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...
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.