I'm not going to take full credit for writing this program, because I wrote a majority of it from an example 800 pages ahead of my class in my C++ book. I do however understand how it's working. I wrote the program so that you can enter your own array in, versus the set array my book was using. There was also an error in the book's program. It had an issue with setting "k=0" in the initial "for" statements, i resolved them but I cannot remember what the problem with them was (I spent like 2 hours on this). There was also an error in the "quicksort" with initializing variable. It might have been a typo on my part, but again i dont remember.
The code is commented to show you that I do have understanding of what I wrote. I don't 100% know how everything works in it, but I do get what and why it's doing what it's doing.
Tuesday, September 28, 2010
Wednesday, September 22, 2010
Is your number here?
The program searches for the number k, the only problem is that you cant enter in a list of numbers that n long. The way it's written, it's limited to 5 inputs. That can be changed to however many is desired, but it's still locked into that that many. I'm not sure how to make it so that can happen.
However, as the program is written, it is successful. You can enter in any number into the a1 - a5 locations, and then it asks for a k. It then searches a1-a5 for k and returns what location it is in if it's there, otherwise returns that the number is not here. It will also finish in finite time.
Subscribe to:
Posts (Atom)