C/C++ Writing a recursive function with no local variables and no loops in C++

  • Thread starter Thread starter franz32
  • Start date Start date
  • Tags Tags
    C++
AI Thread Summary
The discussion revolves around seeking assistance with C++ programming, specifically focusing on the cocktail shaker sort algorithm, which is also known as bubble sort. A user requests the simplest code for this algorithm and inquires about resources for creating a graphical representation of elementary sorting algorithms. In response, a link to a relevant website is provided. The conversation then shifts to writing a recursive function without local variables or loops. The user outlines the requirements for the function, which takes two parameters: a seed (the starting number) and size (the number of columns), and provides examples of expected outputs. A sample implementation of the recursive function is shared, demonstrating how to achieve the desired output format. The user expresses a desire for alternative methods to create a recursive function that adheres to the same restrictions, inviting further contributions from others in the forum.
franz32
Messages
133
Reaction score
0
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:
Technology news on Phys.org
Originally posted by dduardo
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...
 
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...
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top