Generate 10 random numbers (1-100) using bubblesort
Expand Post »
#include<iostream>
using namespace std;
void BubbleSort(int ar[10], int n, int & compare_costs, int & swap_costs)
{
int t; int swaps=-1;
while(swaps)
{
swaps++;
compare_costs++;
for(int i=0; i<n-1; i++)
if(ar[i] > ar[i+1])
{
t=ar[i]; ar[i]=ar[i+1]; ar[i+1]=t;
swap_costs=swap_costs+5;
}
}
}
int main()
{
int n, compare_costs, swap_costs;
int ar[10];
int *bs = new int[n];
int *ss = new int[n];
int *qs = new int[n];
srand(time(0));
for(int i=0; i<n-1; i++)
*(bs+i) = *(ss+i) = *(qs+i) = 1+rand()%100;
Re: Generate 10 random numbers (1-100) using bubblesort
When I run the program it appears:
83 86 77 15 93 35 86 92 49 21
83 77 15 86 35 86 92 49 21 62
It is clearly not sorted and 93 appears on the first output but not the second, and 62 is in the second output but not the first. Why is it doing this ?
Re: Generate 10 random numbers (1-100) using bubblesort
> Last edited by LiquidScorpio81 : 43 Minutes Ago at 18:45.
It's a shame you didn't add the code tags.
"Hey, I know, lets piss off all the people who help around here by continually posting unindented crap."
Doesn't work kiddo. Either we ignore you, or just report the post and wait for a mod to show up in a few hours. Then, if we're still interested, we might just get around to looking at your missive.
Either way, what could have been answered straight away is now delayed until your post gets fixed.
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.