Come in. Sit down. Blaze up. Chill out.
About this Entry
Posted by: Savethiskid

Visit Savethiskid's Xanga Site

Original: 1/20/2005 5:41 PM
Views: 3
Comments: 2
eProps: 2

Read Comments
Post a Comment
Back to Your Xanga Site


Who gave the eProps?
2 eProps!2 eProps! 2 eProps from:
SarahDeEtte

Thursday, January 20, 2005

 try and guess what this does
----------------------------------
import java.util.Random;

public class Sort {
 
  public static int[] sort(int[] array) {
    long start = System.currentTimeMillis(); //stopwatch
    int pointer = 0;
    while (pointer < array.length) {
      int hold = pointer;
    for (int p = pointer; p < array.length; p++) {
      if (array[p] <= array[hold]) { hold = p; }
    }
    swap(pointer, hold, array);
    pointer++;
  }
    System.out.println("Sort time: " + ((System.currentTimeMillis() - start) / 1000.0));
   
  return array;
  }
 
  public static void swap(int a, int b, int[] array) {
    int hold = array[a];
    array[a] = array[b];
    array[b] = hold;
  }
 
  public static int[] random(int length, int max) {
    Random r = new Random();
    int[] array = new int[length];
    for (int p = 0; p < array.length; p++) {
      array[p] = r.nextInt(max);
    }
    return array;
  }
 
  public static void print(int[] array) {
    for (int p = 0; p < array.length; p++) {
      System.out.print(array[p] + " ");
    }
  }
 
  public static void main(String[] args) {
    int[] rand = Sort.random(array_length, max_value);
    Sort.print(rand);
    System.out.println(" ");
    Sort.print(Sort.sort(rand));
  }
 
  static final int array_length = 100;
  static final int max_value = 100;
}
 Posted 1/20/2005 5:41 PM - 3 Views - 2 eProps - 2 comments

Give eProps or Post a Comment

2 Comments

Visit SarahDeEtte's Xanga Site!
I'm pretty sure it is part of your program to take over the world. Yup, I'm positive.
Posted 1/20/2005 9:08 PM by SarahDeEtte - reply

Visit SarahDeEtte's Xanga Site!
socks...
Posted 1/24/2005 4:02 PM by SarahDeEtte - reply


Choose Identity
(?)
 
Give eProps (?)
Post a Comment
Add Link | Preview HTML comment help 


Back to Savethiskid's Xanga Site!
Note: your comment will appear in Savethiskid's local time zone:
GMT -05:00 (Eastern Standard - US, Canada)
The Cam