By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,620 Online
Bytes IT Community
+ Ask a Question
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
  1. while true
  2.           do repeat j--
  3.                  until A[j] <= x
  4.              repeat i++
  5.                  until A[i] >= x
this is from quicksort partition algo. also pls tell me how to write true and repeat until in C
Sep 2 '10 #1
Share this Question
Share on Google+
5 Replies

code green
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
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
  1. #define TRUE   (1)
  2. #define FALSE  (0)
or you can just use 1 as true and 0 as false or you can use
Expand|Select|Wrap|Line Numbers
  1. #include <stdbool.h>
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.

Sep 2 '10 #3

Expert Mod 5K+
P: 9,197
Expand|Select|Wrap|Line Numbers
  1. #define TRUE   (1) 
  2. #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
  1. for(done=FALSE; !done; )
  2.    done = doSomething();
  4. int doSomething(void) {
  5.    return !FALSE;
  6.    }
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

Post your reply

Sign in to post your reply or Sign up for a free account.