InsertInOrder

InsertInOrder - grades[i+1] = grades[i]; } grades[i+1] =...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
public class InsertInOrder{ public static void main(String[ ] args){ int[ ] grades = new int[10]; int nextPlace = 0; //read data into array until sentinel of -1. int grade = IO.readInt( ); while (grade>0){ // move old data up to make a place for new int i; for (i=nextPlace-1; i>=0 & grades[i]>grade; i--){
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: grades[i+1] = grades[i]; } grades[i+1] = grade; nextPlace++; grade = IO.readInt( ); for(int j = 0; j<10; j++){ System.out.println(grades[j]); } } // nextPlace-1 is last index with data System.out.println(" "); for(int i=0; i<nextPlace; i++){ System.out.println(i + " " + grades[i]); } } }...
View Full Document

This note was uploaded on 07/12/2009 for the course CS 111 taught by Professor Hari during the Fall '08 term at Rutgers.

Ask a homework question - tutors are online