473,657 Members | 2,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3055
On Dec 17, 10:04 am, "Joah Senegal" <blo...@hva.nlw rote:
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)continu e;
//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
11650
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 more information how I avoid the scientific notation when I use the CHAR() function to convert a DOUBLE or FLOAT ? What I want is "MagicFunction" in the following pseudocode: myVarchar = MagicFunction(123.0003);
2
8592
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 in pseudocode? Thankyou --
2
3755
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 to the ID of the parent post. I'm trying to convert this into a tree structure in memory (e.g. XML). I understand this can be done with recursion but my algorithm seems to be too slow, i.e. there are too many loops. Does anyone have an example...
19
2970
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 provide an open TD with a DIV in it for the content of this formlet. (The DIV is for DHTML to hide and show the content) I've created a web page showing step by step the two problems I'm encountering. This problem is much easier to see than it...
10
1682
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 records. This is a nice use of threading because those internet requests are going against 3rd party servers that often have 1 second latency problems and so handling them with multiple threads is the fastest way to get through all the records in...
7
2494
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 answers to. First, we have a lot of UserControls. I am getting the error "Type uc_mc_btn_footer is not defined." where uc_mc_btn_footer is the name of the UserControl. Also, on almost all of our UserControls the conversion has remmed out all my code...
9
1404
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 with threads and am looking for some pointers on how to implement, and if the lower level modules/objects need to be rewritten to use threading.local for all local variables. I have a module that communicates with a hardware device, which reads...
10
2125
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 System.Web.Services Imports System.Web.Services.Protocols Imports System.ComponentModel <System.Web.Services.WebService(Namespace:="http:// wwwpreview.#deleted#.co.uk/~ptaylor/Customer.wsdl")_
5
9359
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 display the count, total, and average of the numbers entered. The pseudocode for the program is: Start Enter user's input Begin Loop
0
8403
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8737
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8509
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8610
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7345
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6174
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4327
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.