PROGRAMMING ASSIGNMENT I

Slides:



Advertisements
Similar presentations
CS324e - Elements of Graphics and Visualization A Little Java A Little Python.
Advertisements

Session 3 Algorithm. Algorithm Algorithm is a set of steps that are performed to solve a problem. The example below describes an algorithm Example Check.
Horstmann chapter 8 continued. Sorting arrays The telephone book is easy to use, because the entries are sorted Sorting is a common task, and many many.
1 One-Dimensional (1-D) Array Overview l Why do we need 1-D array l 1-D array declaration and Initialization l Accessing elements of a 1-D array l Passing.
Computer Programming Lab(5).
03/16/ What is an Array?... An array is an object that stores list of items. Each slot of an array holds an individual element. Characteristics.
Copyright © Curt Hill Mathematics Functions An example of static methods.
Ics202 Data Structures. class Array { protected Object[] data; protected int base; public Array (int n, int m) { data = new Object[n]; base = m; } public.
CSC 172 DATA STRUCTURES. SORTING Exercise : write a method that sorts an array. void mysort(int [] a) { }
Lecture 8 Using casts, Strings and WordUtil. Agenda Generating random numbers Casts – Casting a double into an int – Casting an int into a char – Casting.
Writing Static Methods Up until now, we have been USING (calling) static methods that other people have written. Now, we will start CREATING our own static.
Chapter 6 Arrays 1 Fall 2012 CS2302: Programming Principles.
Array Size Arrays use static allocation of space. That is, when the array is created, we must specify the size of the array, e.g., int[] grades = new int[100];
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
3/21/2016IT 2751 Tow kinds of Lists Array What can be done? What can be easily done? student 1 student 2 student 3 student 4 Linked List student 2 student.
Methods. Creating your own methods Java allows you to create custom methods inside its main body. public class Test { // insert your own methods right.
Introduction to programming in java Lecture 05 Review of 1 st four lectures and Practice Questions.
Chapter 5 Arrays F Introducing Arrays F Declaring Array Variables, Creating Arrays, and Initializing Arrays F Passing Arrays to Methods F Copying Arrays.
Building Java Programs Chapter 7 Arrays Copyright (c) Pearson All rights reserved.
Array in C# Array in C# RIHS Arshad Khan
Chapter 2 Clarifications
Exercise 1- I/O Write a Java program to input a value for mile and convert it to kilogram. 1 mile = 1.6 kg. import java.util.Scanner; public class MileToKg.
Arrays (review) CSE 2011 Winter May 2018.
Write code to prompt for 5 grades, read them in, print “Thank you”, then reprint the 5 grades and their average. System.out.println(“Please enter grade.
Building Java Programs
C++ Arrays.
Function Call Trace public class Newton {
Building Java Programs
An Introduction to Java – Part I
Chapter 8: Collections: Arrays
Building Java Programs
Arrays An Array is an ordered collection of variables
Pass by Reference, const, readonly, struct
Chapter 6 Arrays Solution Opening Problem
Selection sort Given an array of length n,
CS 302 Week 8 Jim Williams, PhD.
Chapter 6 Arrays Fall 2012 CS2302: Programming Principles.
Sorts on the AP Exam Insertion Sort.
محاور المحاضرة خوارزمية الفقاعات الهوائية (Bubble Sort)
Building Java Programs
Building Java Programs
CIS 110: Introduction to Computer Programming
Building Java Programs
AP Java 10/4/2016.
Announcements Lab 7 due Wednesday Assignment 4 due Friday.
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
Arrays.
Array Lists CSE 1310 – Introduction to Computers and Programming
Chapter 6 Arrays.
Week 4 Lecture-2 Chapter 6 (Methods).
By Yogesh Neopaney Assistant Professor Department of Computer Science
Suggested self-checks: Section 7.11 #1-11
The Generic List<> Collection class
Building Java Programs
Exercise 5 1. We learned bubble sort during class. This problem requires you to modify the code for bubble sorting method to implement the selection sorting.
Building Java Programs
Building Java Programs
Array Review Selection Sort
Agenda Remarks about last homeworks Class methods(static methods)
Arrays Wellesley College CS230 Lecture 02 Thursday, February 1
Insertion Sort and Shell Sort
CSE 373 Sorting 2: Selection, Insertion, Shell Sort
CIS 110: Introduction to Computer Programming
CS 165: Project in Algorithms and Data Structures Michael T. Goodrich
Stacks, Queues, ListNodes
RANDOM NUMBERS SET # 1:
MIS 222 – Lecture 12 10/9/2003.
Sorting Algorithms.
Presentation transcript:

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.