• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Having trouble with my Sorting Program

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm writing a Sorting program that prompts the user to enter a filename and then opens the file. It will read the comment from the first line and also read an integer N from the second line. It then reads N integers from the rest of the file and puts them into consecutive locations in an array. Once it does all this the program will then write the name of the input file and will sort an identical copy of the array using selection sort and merge sort(two classes that I have already. it finally writes a report of the number of compares and moves done in each sort and then asks the user if he wishes to continue.

My program as of right now asks the user for the text file and prints out whats inside. I'm having trouble with where i need it to write the name of the input file and will sort an identical copy of the array using selection sort and merge sort. I also am having trouble making it write the report of the number of compares and moves done in each sort.

This is what my program is supposed to look like when it outputs:

Enter Filename: ord50
File Name: ord50

File Comment: This is an ordered list of 50 numbers.

selection sort starting ... done
merge sort starting ... done
Here are the results of the sorts:

compares moves

selection sort 1225 147
merge sort 153 572

How can i go about making my program print like this?

Here's my code so far, i have three classes; driver class, mergesort class, and selection class.

Driver class:



MergeSort class:



Selection class:

reply
    Bookmark Topic Watch Topic
  • New Topic