- 作业标题:CSCI 2110 - Data Structures and Algorithms - lab 10
- 课程名称:Dalhouse University CSCI 2110 Data Structures and Algorithms
- 完成周期:2天
Note 1: This is an optional lab meant mainly for students who may have missed more than one lab
during the semester. A total of 8 labs will be taken for grading.
If you have completed 9 labs, the best 8 out of 9 labs will be taken for grading.
If you complete 10 labs, the best 8 out of 10 labs will be taken for grading.
Note 2: There is no in-person lab this week. One TA will be available remotely for help during the
lab times.
Marking Scheme
Each exercise carries 10 points.
Working code, Outputs included, Efficient, Good basic comments included: 10/10
No comments or poor commenting: subtract one point
Unnecessarily inefficient: subtract one point
No outputs and/or not all test cases covered: subtract up to two points
What to submit:
Submit one ZIP file containing all source code (files with .java suffixes) and text documents containing
sample outputs. For each exercise you will minimally have to submit a class containing your completed
methods, a demo class, and sample outputs.
Your final submission should include the following files: Exercise1.java, Exercise1out.txt, and any other
files needed to run your solution.
You MUST SUBMIT .java files that are readable. If you submit files that are unreadable such as .class,
you will lose points. Please additionally comment out package specifiers.
We studied HeapSort in the lectures. There are several other sorting algorithms. One of the earliest, and
not so efficient, sorting algorithm is BubbleSort. In this lab, you will experiment by implementing this
algorithm.
Bubble Sort Algorithm
The Bubble Sort algorithm is used to sort an unsorted list. The algorithm functions via neighbour
to neighbour comparisons of elements within the list and performing a swap of the elements to achieve
the correct order. Multiple iterations of swaps may be required to fully order the list.
。。。
Exercise 1
For this exercise, you will implement two generic static methods to bubble sort an array Integers or Strings.
- You program must be able to sort from min to max and max to min of the values in the array.
- Use the compareTo() method to achieve integer order comparisons and String lexicographic
comparisons. - Use the following method headers:
public static <T extends Comparable<T>> T[] bubbleSortMin (T[] list)
- Sorts from least to greatest
public static <T extends Comparable<T>> T[] bubbleSortMax (T[] list)
- Sorts from greatest to least
Your program should prompt the user for the following information:
- Total size of the list to be sorted
- Sorting Strings or Integers
- Values of the list
- Sorting Min or Max
。。。