473,392 Members | 1,366 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,392 software developers and data experts.

converting some simple pseudocode to c++

Hello all,

I;m a beginner C++ and I;m trying to convert some pseudocode into C++. Its
pseudo code of the peterson algorithm for N-processes.

I almost converted the whole code. But the last lines are very hard.

This is the pseudo code:

for [ k=1 to n except k==i ]

This is pretty simple code although I don;t know how to convert in into c++
because of the except in the pseudocode. for [k=1 to n] to c++ is for
(k=1;k<n;k++). i dont understand it because of the except.

Is there anyone who can tell me what the C++ code is for the above pseudo
code?

I;ve another little bit more complex part of pseudocode as well

wait until ((for all k<>i q[k]<j) or (turn[j]<>i)).

Is there anyone who can give me the c-code for one of this pseudo codes ? I
would be very gratefull if anyone can translate one of the pseudocodes. this
one is the most important

for [ k=1 to n except k==i ]

many many thanks!!!!
Dec 17 '07 #1
2 3033
On Dec 17, 10:04 am, "Joah Senegal" <blo...@hva.nlwrote:
Hello all,

I;m a beginner C++ and I;m trying to convert some pseudocode into C++. Its
pseudo code of the peterson algorithm for N-processes.

I almost converted the whole code. But the last lines are very hard.

This is the pseudo code:

for [ k=1 to n except k==i ]

This is pretty simple code although I don;t know how to convert in into c++
because of the except in the pseudocode. for [k=1 to n] to c++ is for
(k=1;k<n;k++). i dont understand it because of the except.

Is there anyone who can tell me what the C++ code is for the above pseudo
code?

I;ve another little bit more complex part of pseudocode as well

wait until ((for all k<>i q[k]<j) or (turn[j]<>i)).

Is there anyone who can give me the c-code for one of this pseudo codes ? I
would be very gratefull if anyone can translate one of the pseudocodes. this
one is the most important

for [ k=1 to n except k==i ]

many many thanks!!!!
for(int k=1,k!=n;++k){
if(k==i)continue;
//do stuff
}
Dec 17 '07 #2
Joah Senegal wrote:
I;m a beginner C++ and I;m trying to convert some pseudocode into
C++. Its pseudo code of the peterson algorithm for N-processes.

I almost converted the whole code. But the last lines are very hard.

This is the pseudo code:

for [ k=1 to n except k==i ]

This is pretty simple code although I don;t know how to convert in
into c++ because of the except in the pseudocode. for [k=1 to n] to
c++ is for (k=1;k<n;k++).
Note that in Lance's answer the condition for the loop is k<=n, not
k<n like you gave here.
i dont understand it because of the except.

Is there anyone who can tell me what the C++ code is for the above
pseudo code?

I;ve another little bit more complex part of pseudocode as well

wait until ((for all k<>i q[k]<j) or (turn[j]<>i)).
Since C++ does not have "wait" equivalent, you might want to give
more context to see if the translation is possible. Of course,
most likely, due to 'for all' a single-line translation isn't what
you'd naturally come up with. 'for all' needs a loop. Even if
you manage to utilise standard function like 'for_each' or some
such, you would still most likely need a functor, which will be
written as a separate class. For now this is what it looks like
to me:

wait_here:
// wait somehow

bool all_q_are_less_than_j = true;
for (int k = start_k; k <= end_k; ++k) { // start_k, end_k???
if (k != i && !(q[k] < j)) {
all_q_are_less_than_j = false;
break;
}
}
// here is your 'until'
if (all_q_are_less_than_j || turn[j] != i)
// do something, like move forward or whatever...
else
goto wait_here;

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Dec 17 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kent Lewandowski | last post by:
Hi, I saw this post from 3 years ago regarding converting DOUBLE values to CHAR in ibm DB2. Now I'm having the same problem. No real solution was posted to that old thread. Has anyone got...
2
by: Krisitne | last post by:
I need to use a for statement to write some pseudocode. I am not sure how to actually write it - using a for loop. Could someone please give me an example of what a for statment would look like...
2
by: Oleg Ogurok | last post by:
Hi all, I'm looking for a fast algorithm to do the following: A DataTable has the following columns: ID, ParentID, Title, Body, etc. It represents webforum conversation threads. ParentID points...
19
by: Dales | last post by:
I have a custom control that builds what we refer to as "Formlets" around some content in a page. These are basically content "wrapper" sections that are tables that have a colored header and...
10
by: HK | last post by:
With VB.NET 2005, and a Windows Form, running on a dual CPU box, I need to take a recordset (e.g. 100,000 records) and spawn a thread to handle an internet XML transaction routine for each of the...
7
by: Coleen | last post by:
Does anyone have any good detailed information on the conversion process? We are in the process of converting 2 projects from 2003 to 2005 and have some conversion errors that I can not find...
9
by: jdlists | last post by:
I have inheirted some existing code, that i will explain in a moment, have needed to extend and ultimately should be able to run in threads. I've done a bunch of work with python but very little...
10
by: Phillip Taylor | last post by:
Hi guys, I'm looking to develop a simple web service in VB.NET but I'm having some trivial issues. In Visual Studio I create a web services project and change the asmx.vb file to this: Imports...
5
by: just curious | last post by:
Create a C++ console application that uses a while loop to count, total, and average a series of positive integers entered by a user. The user enters a 1 to signal the end of data input and to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.