![]() |
| ||
| Generate 10 random numbers (1-100) using bubblesort #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; for(int i=0; i<n-1; i++) cout<< *(bs+i)<< " "; BubbleSort(bs,n,compare_costs,swap_costs); cout<<endl; for(int i=0; i<n-1; i++) cout<< *(bs+i)<< " "; } |
| ||
| Re: Generate 10 random numbers (1-100) using bubblesort Well, and your question is... ??? |
| ||
| 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. |
| ||
| Re: Generate 10 random numbers (1-100) using bubblesort #include<iostream> |
| ||
| Re: Generate 10 random numbers (1-100) using bubblesort how do i indent ? i press tab and it just tabs over to the reply button |
| ||
| Re: Generate 10 random numbers (1-100) using bubblesort Quote:
And the simplest form of using code tags is [code] your code here ... [/code] |
| ||
| Re: Generate 10 random numbers (1-100) using bubblesort Quote:
|
| ||
| Re: Generate 10 random numbers (1-100) using bubblesort Quote:
|
| ||
| Re: Generate 10 random numbers (1-100) using bubblesort Quote:
#include<iostream> |
| All times are GMT -4. The time now is 4:34 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC