473,385 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Trying Something New To Experiment with


Im tring an experiment that will generate 7000 integer random numbers and
save them in an array. Then I need to copy these 7000 values into a second
array, so that I have two identical integer arrays.
In a function, I want to sort the first array with an un-optimized bubble
sort.
In a second function, I want to sort the second array with an optimized
bubble sort.

So in the main, I would like to print out the time each sort routine took
to execute and print out a message determining which sort routine was
faster.

Any Ideas, I made this one up for fun to also learn how to do arrays and
counts.
Any help would be appreciated.....

--
Message posted using http://www.talkaboutprogramming.com/group/comp.lang.c/
More information at http://www.talkaboutprogramming.com/faq.html

Sep 17 '07 #1
6 1301
On Mon, 17 Sep 2007 04:18:57 -0400, joebenjamin wrote:
Im tring an experiment that will generate 7000 integer random numbers and
save them in an array. Then I need to copy these 7000 values into a second
array, so that I have two identical integer arrays.
In a function, I want to sort the first array with an un-optimized bubble
sort.
In a second function, I want to sort the second array with an optimized
bubble sort.
Optimized bubble sort?
So in the main, I would like to print out the time each sort routine
took to execute and print out a message determining which sort routine
was faster.
#include <time.h>
int main(void)
{
clock_t start, end;
double t0, t1;
start = clock();
func0(arr0, 7000);
end = clock();
t0 = (double)(end - start) / CLOCKS_PER_SEC;
/* Now t0 is the *processor* time elapsed by func0. Repeat the
* same for func1, compare them, print them, etc. */
return 0;
}
Any Ideas, I made this one up for fun to also learn how to do arrays and
counts.
Is there anybody still taking bubblesort seriously? Isn't it just a
teaching toy? No, I'm told that it predates selection sort and insertion
sort... But I still can't imagine how anybody could come up with something
like that having serious purposes.

--
Army1987 (Replace "NOSPAM" with "email")
If you're sending e-mail from a Windows machine, turn off Microsoft's
stupid “Smart Quotes” feature. This is so you'll avoid sprinkling garbage
characters through your mail. -- Eric S. Raymond and Rick Moen

Sep 17 '07 #2
joebenjamin wrote:
) Im tring an experiment that will generate 7000 integer random numbers and
) save them in an array. Then I need to copy these 7000 values into a second
) array, so that I have two identical integer arrays.
) In a function, I want to sort the first array with an un-optimized bubble
) sort.
) In a second function, I want to sort the second array with an optimized
) bubble sort.
)
) So in the main, I would like to print out the time each sort routine took
) to execute and print out a message determining which sort routine was
) faster.
)
) Any Ideas, I made this one up for fun to also learn how to do arrays and
) counts.

I'm not sure what it is you want help with... In any case, this may be
useful: (Quoted from the manual:)

The clock() function determines the amount of processor time used since
the invocation of the calling process, measured in CLOCKS_PER_SECs of a
second.

SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
Sep 17 '07 #3
joebenjamin wrote:
>
Im tring an experiment that will generate 7000 integer random
numbers and save them in an array. Then I need to copy these 7000
values into a second array, so that I have two identical integer
arrays. In a function, I want to sort the first array with an
un-optimized bubble sort. In a second function, I want to sort
the second array with an optimized bubble sort.

So in the main, I would like to print out the time each sort
routine took to execute and print out a message determining which
sort routine was faster.
Sounds simple, so just do it. However you should realize that a
bubble sort is fundamentally unsound in that it is inefficient.
Also, you don't need to save the original sequence (unless you have
other different uses for it) since you can save the initializing
value for the rand (or random) function, and thus reset it to
regenerate the same sequence.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from http://www.teranews.com

Sep 17 '07 #4
Army1987 wrote:
>
On Mon, 17 Sep 2007 04:18:57 -0400, joebenjamin wrote:
Any Ideas, I made this one up for fun
to also learn how to do arrays and counts.
Is there anybody still taking bubblesort seriously?
He said "for fun".
Isn't it just a teaching toy?
That's also what he said.

--
pete
Sep 17 '07 #5
pete wrote:
Army1987 wrote:
>On Mon, 17 Sep 2007 04:18:57 -0400, joebenjamin wrote:
>>Any Ideas, I made this one up for fun
to also learn how to do arrays and counts.
>Is there anybody still taking bubblesort seriously?

He said "for fun".
>Isn't it just a teaching toy?

That's also what he said.
It smelled like homework to me.

--
Tor <torust [at] online [dot] no>
Sep 17 '07 #6
Tor Rustad wrote:
>
pete wrote:
Army1987 wrote:
On Mon, 17 Sep 2007 04:18:57 -0400, joebenjamin wrote:
>Any Ideas, I made this one up for fun
to also learn how to do arrays and counts.
Is there anybody still taking bubblesort seriously?
He said "for fun".
Isn't it just a teaching toy?
That's also what he said.

It smelled like homework to me.
I wrote one for fun and to learn a little about sorting.

http://www.mindspring.com/~pfilandr/...ver/e_driver.c
http://www.mindspring.com/~pfilandr/C/e_driver/

--
pete
Sep 17 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Larry | last post by:
I am a C++/Java programmer trying to get going with some simpe xml transformations at work here. I bought the O'Reilly book Learning xlst for kicks. Someone at work sent me this xml shown below,...
6
by: MLH | last post by:
I'm new to A97 - moving up from Access 2.0 and Access Basic. Would like to build a fundamental, sound understanding of class modules. Is there a site with an example of a simplistic class module...
6
by: Steven | last post by:
Hi, I am trying to position 2 columns of links so that the first is at the left of the page and the second is at the right. The lines in each column should be left-justified. I have managed...
8
by: Merlin | last post by:
Ok.... I feel really dumb on this one, because I had previously figured it out, and now don't have a clue. I'm trying to get the user to input a new filename (via an integer variable) and...
12
by: Jim Anderson | last post by:
This is my first attempt at XML documentation. I'm trying to get started with docbook so I can put a set of documentation into docbook tags. I'm using 'XML In A Nutshell" and "DocBook The...
54
by: CoreyWhite | last post by:
The following experiment is a demonstration of TIME TRAVEL. When writing this program, and testing it out I found that sometimes the program would engage itself in time travel but other times it...
0
by: egbert | last post by:
As an exercise in the use of dispatcher I concocted a Zoo with some Animals, see below. It works, but I think it is convoluted, obfuscated. The idea is that in the Zoo each animal needs its own...
15
by: r0g | last post by:
Hi There, I know you can use eval to dynamically generate the name of a function you may want to call. Can it (or some equivalent method) also be used to do the same thing for the variables of a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.