424,968 Members | 1,620 Online
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

convert pseudocode into C code

 P: 2 hi... can anyone tell me how to convert the below pseudocode segment to a C program Expand|Select|Wrap|Line Numbers while true           do repeat j--                  until A[j] <= x              repeat i++                  until A[i] >= x   this is from quicksort partition algo. also pls tell me how to write true and repeat until in C thnxx Sep 2 '10 #1
5 Replies

 Expert 100+ P: 1,726 It seems odd that you are asking us to write a piece of code for you when you have the algorithm. Your questions suggest you don't know C at all, so if learning why start with something so tricky? Sep 2 '10 #2

 Expert 2.5K+ P: 3,112 Hi! This code is very c-like, so you don't have to change much. What you'll be using is called "loops" and there's a tutorial here, that should point you in the right direction. One tip from me: You're going to need 2 of the 3 types of loops that you'll find in that article. Oh, and in C you don't have predefined values true and false, but you can either define them yourself by putting the following code in the head of your program: Expand|Select|Wrap|Line Numbers #define TRUE   (1) #define FALSE  (0) or you can just use 1 as true and 0 as false or you can use Expand|Select|Wrap|Line Numbers #include  to define the datatype bool which can have the values true and false... Or I'm sure there are other ways to do it too. Greetings, Nepomuk Sep 2 '10 #3

 Expert Mod 5K+ P: 9,197 Expand|Select|Wrap|Line Numbers #define TRUE   (1)  #define FALSE  (0)  You might want to #define TRUE as !FALSE. All values are TRUE that are not FALSE. Sep 2 '10 #4

 Expert 100+ P: 2,396 You might want to remove the definition for TRUE. I suggest that you only work with the FALSE macro. Expand|Select|Wrap|Line Numbers for(done=FALSE; !done; )    done = doSomething();   int doSomething(void) {    return !FALSE;    } Whatever value you may choose for your TRUE macro, there will be many values that differ from TRUE, but that are still logically true. However, if you're using C99 then you should include stdbool.h and use the facilities it provides. Sep 2 '10 #5

 P: 2 thnxx guys...:D Sep 3 '10 #6