- #1
emmadun
- 8
- 0
- Homework Statement
- In a bar, drinks consist of n-ingredients, conveniently numbered from 1 to n, added to a shaker in some random order. You have to mix them properly to have them ordered increasingly, that is sorted. You can perfromr operations of left and right shakes.
The task is: perform a minimum number of shakes to prepare the drink. Be quick!
- Relevant Equations
- Right shake is equivalent to:
For place:=1 to N-1 do:
If(ingredient(place)>ingredient(place+1)) swapIngredients(place, place+1);
A left shake is very similar and equivalent to:
For place:=N-1 downto 1 do:
If (ingredient(place)>ingredient(place+1)) swapIngredients (place, place+1));
I attempted going with c++ and this is what i got:
from here, i wanted to order the ingredients increasingly using an array but i don't think my approach to the problem is correct.
Any ideas anyone might have?[/i]
C:
#include <iostream>
Using namespace std;
int i, j, keeper, n;
int Ingredients[100], Blender[100],
cout<<”How many ingredients does the shake need?”<<endl;
cin>>n;
cout<<”Type down the ingredients:”<<endl;
for(i=1; i<=n; i++)
{
Cout<<”ingredients[“<<i<<”]=”;
Cin>>Ingredients[i];
}
Any ideas anyone might have?[/i]
Last edited by a moderator: