1 / 4

PROGRAMMING ASSIGNMENT I

PROGRAMMING ASSIGNMENT I. Write a program to implement Shell Sort

Download Presentation

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