Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

General Discussions


You are currently viewing our General Discussions as a guest. Please register to participate.
Login



Closed Thread
Old 05-04-2007, 03:49 PM C++ buble sort
Junior Talker

Posts: 2
Name: death
Trades: 0
hey i need a program for this problem

-[FONT='Times New Roman','serif']Create a program that has a searchable array of 100 distinct positive integers between 0 and 1000. Your program should first create the 100 element array and fill it with random numbers. Once [/FONT][FONT='Times New Roman','serif']the[/FONT][FONT='Times New Roman','serif'] array is filled, you need to sort it using either a bubble or selection sort. Finally, you will ask the user to enter a number and the program will search the array to find whether it is contained [/FONT][FONT='Times New Roman','serif']among[/FONT][FONT='Times New Roman','serif'] the array's random numbers. The user will be rewarded with a message saying at which element the number was found, or else that the number was not found. The user will be prompted [/FONT][FONT='Times New Roman','serif']to[/FONT][FONT='Times New Roman','serif'] search for additional numbers if they wish and when the user finishes, the program will output the array in rows of ten numbers each.[/FONT]
[FONT='Times New Roman','serif'][/FONT]
[FONT='Times New Roman','serif']- thanks[/FONT]
quest23 is offline
View Public Profile
 
 
Register now for full access!
Old 05-04-2007, 07:15 PM Re: C++ buble sort
Village Idiot's Avatar
Webmaster Talker

Posts: 535
Trades: 0
Unless there is some kind of pay, im not going to do all of it, but here is the sorting. Also, why didnt you take the time to make your message readable (no font tags)

ps. Am I doing your homework?


Quote:
#include <iostream>
using namespace::std;
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(int argc, char **argv)
{
//seed rand
srand( time(NULL) );

//the number of elements in the array
int elements=100;

//assign the array
int arr[elements];

//set each element
for(int i=0;i<elements;i++)
{
arr[i] = rand()%1000;
}

//this bool tells the loop to stop or continue
bool stop=false;

//this int holds the number while it is being swapped
int temp;

//sort them (this is bublesort)
while(stop == false)
{
stop = true;
for(int j=0;j<elements-1;j++)
{
if(arr[j] > arr[j+1])
{
temp = arr[j+1];
arr[j+1] = arr[j];
arr[j] = temp;
stop = false;
}
}
}

//display them
for(int k=0;k<elements;k++)
{
cout << arr[k] << "\n";
}
cout << "Press any key to exit";
//pause the program, any variable would work in place of temp
cin.get();

}
__________________
I have the heart of a child, I keep it in a jar on my desk.

Last edited by Village Idiot; 05-04-2007 at 07:21 PM..
Village Idiot is offline
View Public Profile
 
Old 05-05-2007, 05:20 AM Re: C++ buble sort
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,380
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
cross post with

http://www.webmaster-talk.com/coding...t-c-array.html
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
View Public Profile Visit chrishirst's homepage!
 
Closed Thread     « Reply to C++ buble sort
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.90005 seconds with 12 queries