Main Page   Compound List   File List   Compound Members   File Members  

sort.c

Go to the documentation of this file.
00001 /* sort.c 
00002  *    Test program to sort a large number of integers.
00003  *
00004  *    Intention is to stress virtual memory system.
00005  *
00006  *    Ideally, we could read the unsorted array off of the file system,
00007  *      and store the result back to the file system!
00008  */
00009 
00010 #include "syscall.h"
00011 
00012 int A[1024];    /* size of physical memory; with code, we'll run out of space!*/
00013 
00014 int
00015 main()
00016 {
00017     int i, j, tmp;
00018 
00019     /* first initialize the array, in reverse sorted order */
00020     for (i = 0; i < 1024; i++)          
00021         A[i] = 1024 - i;
00022 
00023     /* then sort! */
00024     for (i = 0; i < 1023; i++)
00025         for (j = i; j < (1023 - i); j++)
00026            if (A[j] > A[j + 1]) {       /* out of order -> need to swap ! */
00027               tmp = A[j];
00028               A[j] = A[j + 1];
00029               A[j + 1] = tmp;
00030            }
00031     Exit(A[0]);         /* and then we're done -- should be 0! */
00032 }

Generated on Mon Feb 10 09:54:47 2003 for nachos by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002
The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees