Need help on quick sort - v.Urgent

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • needhelp123
    New Member
    • May 2007
    • 21

    Need help on quick sort - v.Urgent

    Can any one send me a quick sort simple logic pogram...

    its very urgent urgent
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by needhelp123
    Can any one send me a quick sort simple logic pogram...

    its very urgent urgent
    Why don't you try to write one yourself? Do you know the algorithm?

    Comment

    • needhelp123
      New Member
      • May 2007
      • 21

      #3
      Originally posted by r035198x
      Why don't you try to write one yourself? Do you know the algorithm?
      [CODE=java] public class QuickSort {
      int i; // Array index

      int j; // Array index

      /**
      * @precondition Unsorted elements
      * @postcondition Sorted elements
      * @param qsArrays
      * @param len
      */
      public void setQuickSort(in t qsArrays[], int len) {
      setQuicksort(qs Arrays, 0, len - 1);
      }

      private void setQuicksort(in t qsArrays[], int left, int right) {
      int middle = left;

      //block where array division starts
      swap(qsArrays, left, (left + right) / 2);
      for (int i = left + 1; i <= right; i++) {
      if (qsArrays[i] <= qsArrays[left]) {
      middle++;
      //recursive function for swap
      swap(qsArrays, i, middle);
      }
      }

      //recursive method o divide array into its child
      swap(qsArrays, left, middle);

      // Blockfor soerting arrays after the list is divided into sub array
      if (left + 1 < middle) {
      setQuicksort(qs Arrays, left, middle - 1);
      }

      if (middle + 1 < right) {
      setQuicksort(qs Arrays, middle + 1, right);
      }
      } // end setQuicksort

      /**
      * Swap numbers
      *
      * @param list
      * @param a
      * @param b
      */
      private void swap(int list[], int a, int b) {
      int temp = list[a]; //temp holds first number
      list[a] = list[b]; //first index holds a value second index
      list[b] = temp; // second index value holds a value of temp variable
      }

      /**
      * The main method illustrates the use of a quick sort to sort a
      * small array with 5 values
      * @precondition: (None)
      * @Postcondition: Sorted Array
      */
      public static void main(String str[]) {
      //array Initialization
      int[] qsArrays = new int[5];

      //insert elements into array
      qsArrays[0] = 20;
      qsArrays[1] = 10;
      qsArrays[2] = 50;
      qsArrays[3] = 100;
      qsArrays[4] = 05;

      // Print the array before sorting:
      System.out.prin tln("Data before Soring ");
      System.out.prin tln("********** ****** ");

      //block to print unsorted elements
      for (int val = 0; val < 5; val++) {
      System.out.prin tln("Value at index" + val + " = " + qsArrays[val]);
      }

      QuickSort acc = new QuickSort();
      acc.setQuickSor t(qsArrays, 5); //calling setQuickSort method

      System.out.prin tln(" ");
      System.out.prin tln(" ");
      System.out.prin tln("Data After Soring");
      System.out.prin tln("********** ******");

      //block to print sorted elements
      for (int val = 0; val < 5; val++) {
      System.out.prin tln("Value at index" + val + " = " + qsArrays[val]);
      }
      }
      }
      [/CODE]
      this is complex... i need simple.....
      Last edited by r035198x; May 22 '07, 06:04 PM. Reason: added code tags

      Comment

      • prometheuzz
        Recognized Expert New Member
        • Apr 2007
        • 197

        #4
        Originally posted by needhelp123
        ...

        this is complex... i need simple.....
        Here ya go:

        [CODE=java]public class ReallyQuickSort {

        static void display(String message, int[] array) {
        System.out.prin t(message);
        for(int i = 0; i < array.length; i++) {
        System.out.prin t(array[i]+" ");
        }
        }

        static void sort(int[] array) {
        java.util.Array s.sort(array);
        }

        public static void main(String[] args) {
        int[] array = {20, 10, 50, 100, 5};
        display("Before sorting: ", array);
        sort(array);
        display("\nAfte r sorting: ", array);
        }
        }[/CODE]

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by needhelp123
          this is complex... i need simple.....
          That quicksort implementation is as simple as they come. Don't just try to scrape
          "TeH CoDeZ!!!11eleve n UGRENT" from the internet; think for yourself instead.

          kind regards,

          Jos

          Comment

          • needhelp123
            New Member
            • May 2007
            • 21

            #6
            Originally posted by JosAH
            That quicksort implementation is as simple as they come. Don't just try to scrape
            "TeH CoDeZ!!!11eleve n UGRENT" from the internet; think for yourself instead.

            kind regards,

            Jos
            do not try to put down any one if u know the concept let me.. kno that program is designed by me.....
            thank you

            Comment

            • needhelp123
              New Member
              • May 2007
              • 21

              #7
              Originally posted by prometheuzz
              Here ya go:

              [CODE=java]public class ReallyQuickSort {

              static void display(String message, int[] array) {
              System.out.prin t(message);
              for(int i = 0; i < array.length; i++) {
              System.out.prin t(array[i]+" ");
              }
              }

              static void sort(int[] array) {
              java.util.Array s.sort(array);
              }

              public static void main(String[] args) {
              int[] array = {20, 10, 50, 100, 5};
              display("Before sorting: ", array);
              sort(array);
              display("\nAfte r sorting: ", array);
              }
              }[/CODE]
              promo,
              before itself i couild have used tahat redimade util package,,,,

              i asked would i be possible for you to update that,,, i mean simler by using the concep what i have,...

              Comment

              • prometheuzz
                Recognized Expert New Member
                • Apr 2007
                • 197

                #8
                Originally posted by needhelp123
                promo,
                before itself i couild have used tahat redimade util package,,,,

                i asked would i be possible for you to update that,,, i mean simler by using the concep what i have,...
                No, I'm done helping you.

                Comment

                • needhelp123
                  New Member
                  • May 2007
                  • 21

                  #9
                  Originally posted by prometheuzz
                  No, I'm done helping you.

                  ok promo.... i am workin ion that sort to make it simple will be complet it by evening

                  Comment

                  • r035198x
                    MVP
                    • Sep 2006
                    • 13225

                    #10
                    Originally posted by needhelp123
                    ok promo.... i am workin ion that sort to make it simple will be complet it by evening
                    Please tell us how it goes.

                    Comment

                    Working...