1 / 4

PROGRAMMING ASSIGNMENT I

This programming assignment focuses on implementing the Shell Sort algorithm in a functional style. The program generates a fixed-size array of random double values, sorts the array using Shell Sort, and demonstrates the sorting process with an array printing function. The main method initializes the random array, prints it before sorting, invokes the shellSort function, and prints the sorted array afterward. Subfunctions include a customized insertion sort for sublists of size k. This assignment is due on June 12 at 5 p.m.

Télécharger la présentation

PROGRAMMING ASSIGNMENT I

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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:

  2. Generate array of random numbers • double a[] = new double[15]; • for (int j = 0; j < a.length; j++) • a[j] = Math.random()*10;

  3. 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); }

  4. 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.

More Related