CipRyaN Posted March 19, 2009 Share Posted March 19, 2009 Ok, what i have to do(@faculty, i'm not gonna say that it's not a homework because IT IS). So, if anybody here knows clisp(Clisp homepage )please help me with some code for implementing the QuickSort method. Thx in advanced. Link to comment Share on other sites More sharing options...
0 Bookieass Posted March 20, 2009 Share Posted March 20, 2009 Ok, what i have to do(@faculty, i'm not gonna say that it's not a homework because IT IS). So, if anybody here knows clisp(Clisp homepage )please help me with some code for implementing the QuickSort method. Thx in advanced. Cant help in CLisp :o Never heard of this language :iiam: But attaching a quicksort algorithm for u in C#... hope u can convert it back to your desired language namespace sortQuick { class quickSort { // array of integers to hold values private int[] a = new int[100]; // number of elements in array private int x; // Quick Sort Algorithm public void sortArray() { q_sort(0, x - 1); } public void q_sort(int left, int right) { int pivot, l_hold, r_hold; l_hold = left; r_hold = right; pivot = a[left]; while (left < right) { while ((a[right] >= pivot) && (left < right)) { right--; } if (left != right) { a[left] = a[right]; left++; } while ((a[left] <= pivot) && (left < right)) { left++; } if (left != right) { a[right] = a[left]; right--; } } a[left] = pivot; pivot = left; left = l_hold; right = r_hold; if (left < pivot) { q_sort(left, pivot - 1); } if (right > pivot) { q_sort(pivot + 1, right); } } public static void Main() { // Instantiate an instance of the class quickSort mySort = new quickSort(); // Get the number of elements to store in the array Console.Write("Number of elements in the array (less than 100) : "); string s = Console.ReadLine(); mySort.x = Int32.Parse(s); // Array header Console.WriteLine(""); Console.WriteLine("-----------------------"); Console.WriteLine(" Enter array elements "); Console.WriteLine("-----------------------"); // Get array elements for (int i = 0; i < mySort.x; i++) { Console.Write("<{0}> ", i + 1); string s1 = Console.ReadLine(); mySort.a[i] = Int32.Parse(s1); } // Sort the array mySort.sortArray(); // Output sorted array Console.WriteLine(""); Console.WriteLine("-----------------------"); Console.WriteLine(" Sorted array elements "); Console.WriteLine("-----------------------"); for (int j = 0; j < mySort.x; j++) { Console.WriteLine(mySort.a[j]); } // Here to stop app from closing Console.WriteLine("\n\nPress Return to exit."); Console.Read(); } } } Program.txt Link to comment Share on other sites More sharing options...
0 CipRyaN Posted March 20, 2009 Author Share Posted March 20, 2009 thx a lot dude, but, i know too iterative programming, i suck at rule based programming(like this clisp). Clisp is more like a expert system making programming environment, it's brothers are lisp and prolog. Link to comment Share on other sites More sharing options...
0 Bookieass Posted March 21, 2009 Share Posted March 21, 2009 thx a lot dude, but, i know too iterative programming, i suck at rule based programming(like this clisp). Clisp is more like a expert system making programming environment, it's brothers are lisp and prolog. Hi.... had used lisp in one of my autocad programming project (self understanding) which is AutoLISP i called it ......... "Lost In Stupid Loops Please" If u need any help on lisp you meanwhile go to http://www.cs.sfu.ca/CC/310/pwfong/Lisp/1/tutorial1.htmlor http://pieterbreed.blogspot.com/2005/07/co...n-tutorial.html I know its not what u want.... but that what i can think off!!! srry :( Link to comment Share on other sites More sharing options...
0 CipRyaN Posted March 21, 2009 Author Share Posted March 21, 2009 ok, i'm a DUMB ASS, it is NOT CLISP it's CLIPS!!...i did some work by myself and this is it..: (deffacts liste (lista 10 9 8 7 6 5 4 3 2 1) (handle) (lower) (upper)) (defrule stare_1 ?a <- (lista ?x $?end_1) ?b <- (handle) => (retract ?a) (retract ?b) (assert (lista $?end_1)) (assert (pivot ?x)) ) (defrule stare_2_1 (pivot ?x $?) ?a <- (lower) ?b <- (lista ?y&:(< ?y ?x) $?end_1) => (retract ?a) (retract ?b) (assert (lower ?y)) (assert (lista $?end_1)) ) (defrule stare_2_2 (pivot ?x $?) ?a <- (upper) ?b <- (lista ?y&:(> ?y ?x) $?end_1) => (retract ?a) (retract ?b) (assert (upper ?y)) (assert (lista $?end_1)) ) (defrule stare_2_3 ?a <- (pivot ?x $?end_1_1) ?b <- (lista ?y&:(= ?y ?x) $?end_1_2) => (retract ?a) (retract ?b) (assert (pivot ?x $?end_1_1 ?y)) (assert (lista $?end_1_2)) ) (defrule stare_3_1 (declare (salience 100)) (pivot ?x $?) ?a <- (lista ?y&:(< ?y ?x) $?end_1_1) ?b <- (lower $?beg_2 ?z&:(< ?z ?y) $?end_2_2) => (retract ?a) (retract ?b) (assert (lista $?end_1_1)) (assert (lower $?beg_2 ?z ?y $?end_2_2)) ) (defrule stare_3_2 (declare (salience 100)) (pivot ?x $?) ?a <- (lista ?y&:(< ?y ?x) $?end_1_1) ?b <- (lower $?beg_2 ?z&:(> ?z ?y) $?end_2_2) => (retract ?a) (retract ?b) (assert (lista $?end_1_1)) (assert (lower $?beg_2 ?y ?z $?end_2_2)) ) (defrule stare_3_3 (declare (salience 100)) (pivot ?x $?) ?a <- (lista ?y&:(> ?y ?x) $?end_1_1) ?b <- (upper $?beg_2 ?z&:(< ?z ?y) $?end_2_2) => (retract ?a) (retract ?b) (assert (lista $?end_1_1)) (assert (lower $?beg_2 ?z ?y $?end_2_2)) ) (defrule stare_3_4 (declare (salience 100)) (pivot ?x $?) ?a <- (lista ?y&:(> ?y ?x) $?end_1_1) ?b <- (upper $?beg_2 ?z&:(> ?z ?y) $?end_2_2) => (retract ?a) (retract ?b) (assert (lista $?end_1_1)) (assert (lower $?beg_2 ?y ?z $?end_2_2)) ) (defrule stare_3_5 (declare (salience 100)) ?b <- (pivot ?x $?end_1) ?a <- (lista ?y&:(= ?y ?x) $?end) => (retract ?a) (retract ?b) (assert (lista $?end)) (assert (pivot ?x $?end_1 ?y)) ) (defrule stare_finala (declare (salience -100)) ?a <- (lista $?) (not (lista ?x)) ?b <- (lower $?smaller) ?d <- (pivot $?pivot) ?e <- (upper $?bigger) => (retract ?a) (retract ?b) (retract ?d) (retract ?e) (assert (lista_finala $?smaller $?pivot $?bigger)) ) it is not such a good code, but i hope i will get a good grade on it.. Link to comment Share on other sites More sharing options...
Question
CipRyaN
Ok, what i have to do(@faculty, i'm not gonna say that it's not a homework because IT IS). So, if anybody here knows clisp(Clisp homepage )please help me with some code for implementing the QuickSort method. Thx in advanced.
Link to comment
Share on other sites
4 answers to this question
Recommended Posts