Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use the C language for this assignment. See page 1092-1093 of C book for argc and argv[] info or google the terms if need be.

Use the C language for this assignment. See page 1092-1093 of C book for argc and argv[] info or google the terms if need be. You need this so that the file that is scanned can have any name whatsoever. See problem 3.4 on page 112. You are going to implement the odd-even sort. You don't need to do any of his instructions concerning listing 3.1. The task will be to sort a file using a single command line file. HOWEVER, I don't want to see the whole sorted file, so the output will simply be any of the ints in the sorted file (that I may specify--see below) when sorted from lowest to highest). So I should be able to query and REPEATEDLY ask for a number in a certain index until I ask for -1 which indicates an invalid index and the program should stop. So, for example, if the index specified is 3 then I want the number in index 3 (which will be the 4th smallest number). Next, I might specify 500 or whatever. Eventually I specify -1 and the program stops. For THIS program I am am going to use gcc on Osprey with a single command line file that will have a very large number of random ints (at least 1000, perhaps significantly more and they might be positive, negative , or zero). The very first number in the file, however, is not actual data, but rather it specifies the number of numbers after it. So you will want to calloc an array to store the data so that the array is the correct size. You can google calloc is you have never used it or you can find some examples in the C book or my website under one of the tabs for C. DO NOT STORE THE VERY FIRST NUMBER IN THE ARRAY. ONLY STORE THE NUMBERS AFTER THAT AND OF COURSE THE SMALLEST NUMBER WILL EVENTUALLY BE STORED IN INDEX 0 (NOT 1). BE CAREFUL WHEN PROGRAMMING AS THERE APPEARS TO BE AN ERROR IN HIS LOGIC. I BELIEVE HE IGNORES THE NUMBER IN INDEX 0. So I will type $ unshar bigone $ gcc *.c $ ./a.out myfile to test your program. The number of ints on a single line is unknown; there might be just one or there might be many. They will be separated by "white space"...blanks, tabs, or newlines. You should use your own test file or files. shar together all your C files and any header file and turn in that file. $ shar -T *.c *.h >bigone $ turnin bigone kmartin.cop3530.a2 NEVER turnin ANY BINARY CODE IN THIS CLASS. NO LATE ASSIGNMENTS ACCEPTED..GET IT DONE EARLY! The following is from a link on my opening BB page called a modular approach to writing C code. It may be useful to you: A modular approach to writing C code. 1. For each function, including main(), f() that is written store it as f.c and put #include "my.h" as first line. Put all functions and my.h in a folder by themselves. You should use at least one other function besides main() 2. Compile each function separately without linking , as in $ gcc -c f.c or to do them all at once $ gcc -c *.c-this produces f.o, etc. 3. Compile and link all .o's together , as in $ gcc *.o 4. $./a.out runs the program or $./a.out myfile etc 5. $ shar *.c my.h >bigone 6. $ turnin bigone kmartin.cop3530.a2 for example. 7. When I get the code, I $ unshar bigone 8. $ gcc -c *.c 9. $ gcc *.o etc In my.h put # include  # include  that you need All function prototypes separated by semicolons All structures separated by semicolons NO variables Your program must compile and run on Osprey using gcc as the compiler. 

image text in transcribed

two 3.4 Another simple sort is the odd-even sort. The idea is to repeatedly make passes through the array. On the first pass you look at all the pairs of liet o atjl and alj+11, where j is odd (j-1, 3, 5, ..). If their key values are uo order, you swap them. On the second pass you do the same for all the values (j = 2, 4, 6, ). You do these two passes repeatedly until the arraywith sorted. Replace the bubblesort() method in bubblesort.java (Listing an oddEvensort() method. Make sure it works for varying amoun You'll need to figure out how many times to do the two passes. 3.1) w ts of data. The odd-even sort is actually useful in a multiprocessing environmet separate processor can operate on each odd pair simultanousy er each pa each even pair. Because the odd pairs are independent of each his can be checked-and swapped, if necessary-by a different proceo and then on ther, each pair makes for a very fast sort

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sql All In One For Dummies 7 Books In One

Authors: Allen G Taylor ,Richard Blum

4th Edition

1394242298, 978-1394242290

More Books

Students also viewed these Databases questions