TEST Weds., FH-123

Download Report

Transcript TEST Weds., FH-123

PROGRAMMING
ASSIGNMENT I
• Write a program to implement Shell Sort
• Write in a functional style—functions for shell
sort, making a call to a function which is a
modification of insertion to sort sublists of size k
(and when k=1, we do regular insertion sort), and
a function printArray that will print out the array
before and after sorting
• The array does not need to be entered by the user;
rather, declare it of fixed size and generate a
random array of elements:
Generate array of random
numbers
• double a[] = new double[15];
•
•
for (int j = 0; j < a.length; j++)
a[j] = Math.random()*10;
My main program
• public static void main(String args[]){
• //Generate an array of length 15 of random nums
• double a[] = new double[15];
•
for (int j = 0; j < a.length; j++)
•
a[j] = Math.random()*10;
•
System.out.println("Before sorting");
•
printArray(a);
•
shellSort(a);
•
System.out.println("After sorting");
•
printArray(a); }
Function call
• In my program, the function shellSort calls
a function that performs the modified
insertion sort
• Program is due Tues., June 12, 5 p.m.