Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
while (swapCounter != 0){
    swaps = 0;
    for (int i = 0; i < 7 - 1; i = i + 1) {
        if (numbers[i] > numbers[i+1]) {
            temp = numbers[i];
            numbers[i] = numbers[i+1];
            numbers[i+1] = temp;
            swaps = swaps + 1;
        }
    }
    swapCounter = swaps;
}
<

What I have tried:

This code is for bubble sort algorithm and i have never written any pseudo code
Posted
Updated 28-Nov-20 8:23am
v2

There is no how, just walk through the code execution flow like a computer, and of course you need to know the language of that code. Do you?
 
Share this answer
 
v2
Think about what each line of code does and then describe that in writing. You don't have to describe every single line of code though. For example, in this algorithm the code in the inner loop could be described like this :
swap values
increment counter

That's all - that is the pseudo code for those four lines inside the inner set of braces. Beyond that, you have two loops, an initialization, and a comparison to describe.
 
Share this answer
 
Just an exercise, I am sure OP found better ways to spent his time.

Start by finding a decent verbal definition of "bubble sort".
Maybe you can even ask Mrs Google to get you a old fashioned flow chat of the
algorithm.
If decent , both should be "language independent".
Then comment EACH code line matching its function to algorithm.
In my view - when code is commented , such comments ARE "pseudo code"
and should be integral part of the design.
Of course your task is reversed - writing code is much easier when
started with even minimal "pseudo code" , not just writing it after coding
is done.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900