Purpose : write a program to sort monomials along decreasing degrees.
A useful application of linear linked lists is to store univariate polynomials of large degrees, but with few monomials with nonzero coefficient. Using arrays to represent such polynomials is wasteful. For efficient manipulation of polynomials, it is necessary to have the monomials in the list sorted, with the highest degree monomial first and the rest following in descending order of the degrees.
The monomials have floating coefficients and their degrees are natural numbers. In case the user gives two or more monomials with equal degrees, you should not add the monomials. Your program must work for empty lists and lists with only one element. Here is an example of a session with the program :
[jan@obelix Project4]$ ./sortmon
Reading a list of monomials.
Give coefficient (0.0 to stop) : 34
Give the degree of the monomial : 2421
Give coefficient (0.0 to stop) : 2
Give the degree of the monomial : 234
Give coefficient (0.0 to stop) : -5
Give the degree of the monomial : 3433
Give coefficient (0.0 to stop) : 9
Give the degree of the monomial : 5
Give coefficient (0.0 to stop) : 0
The list of monomials :
34.000000*x^2421
2.000000*x^234
-5.000000*x^3433
9.000000*x^5
The sorted list of monomials :
-5.000000*x^3433
34.000000*x^2421
2.000000*x^234
9.000000*x^5
[jan@obelix Project4]$
Besides the reading and the printing, the main topic of this
project is to write a function to sort the list of monomials.
In your implementation you must
keep working with lists throughout the program. Solutions that
achieve the sorting by converting the list into an array and
then converting back into a list will be penalized with 20 points
off (the total score is 40 points). One simple algorithm for sorting
is to scan the original list successively for the monomial with the next
smallest degree. Each time this next smallest degree monomial is found,
insert it to the front of a new list.
Because the monomials inserted in this way have increasing degrees,
this new list will be sorted.
The listings of your program will be collected at the start of the lecture on Monday 9 April, at 1PM. Also send the code by e-mail to jan@math.uic.edu. The first line of your program should be like
/* MCS 275 Project Four by <Author> */
where you replace the < Author > by your name.
Write appropriate documentation inside the code to comment on your subroutines. The gcc compiler will be used to test your program. So even if you have developed your program in a Windows environment, it may be good to run your final version on icarus.cc.uic.edu where the gcc compiler is installed. A final note to Windows users: with the Cygwin tools you can use the gnu tools from Windows.
If you have questions, comments, or difficulties, feel free to come to my office for help.