Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Inserted Sort :/
Author Message
Flikerator

Posted: Thu Nov 17, 2005 5:46 pm   Post subject: Inserted Sort :/

 code: var test : array 1 .. 8 of int var temp : int for i : 1 .. 8     test (i) := Rand.Int (1, 99)     put test (i) : 2, " " .. end for put "" procedure move (i : int, j : int)     for ii : i .. j         test (ii) := test (ii + 1)     end for end move for decreasing i : 8 .. 1     for j : i .. 8         if j + 1 > upper (test) then         elsif test (i) < test (j + 1) then             temp := test (i)             move (i, j)         end if     end for end for for i : 1 .. 8     put test (i) : 2, " " .. end for

I have a mind block. This is inserted sort :/ It goes from itself to the end of the array looking for a smaller number. and then it "inserts" itself by moving all the numbers from that number over (The number next to it is put into its place) and that number is placed in the spot where the smallest number was (its over one place remember?). I know im doing something stupid and simple wrong. Any ideas? (It has to do with the move proc)

Paul

Posted: Thu Nov 17, 2005 11:36 pm   Post subject: (No subject)

are you talking about insertion sort?
 code: function insertsort (A : list[0..n-1]) {     var int i, j;     for i from 0 to n - 1     {         value = a[i];         j := i - 1;         while (j >= 0) and (a[j] > value)         {                 a[j+1] = a[j];                 j = j - 1;         }         a[j+1] = value;     } }
Flikerator

Posted: Mon Nov 21, 2005 8:47 am   Post subject: (No subject)

Yes it was insertion, but I figured it out last week (after I sent here).

 code: var temp, hold : int var numbers : array 1 .. 8 of int for i : 1 .. 8     numbers (i) := Rand.Int (1, 99)     put numbers (i) : 2, " " .. end for put "" for decreasing i : 7 .. 1     temp := numbers (i)     hold := i     for j : i .. 8         if temp > numbers (j) then             numbers (j - 1) := numbers (j)             hold := j         end if     end for     numbers (hold) := temp end for for i : 1 .. 8     put numbers (i) : 2, " " .. end for

This is the core of what I have to test and make sure it works. Now onto shell sort
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 3 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: