0

I have been asked to make a simple sort aglorithm to sort a random series of 6 numbers into numerical order. However, I have been asked to do this using Barebones-a theoretical language put forward in the book Computer Science, an Overview.

Some information on the language can be found here.

Just to clarify, I am a student teacher and have been doing anaysis on "mini-programing languages" and their uses in a teaching environment. I suggested to my tutor that I look at barebones (the language) and asked what sort of exmaple program I should write. He suggested a simple sort algorithm. Now since looking at the language I can't understand how I can do this without using arrays and if statements.

The code to swap the value of variables would be

while a not 0 do;
    incr Aux1;
    decr a;
end;
while b not 0 do;
    incr Aux2
    decr b
end;
while Aux1 not 0 do;
    incr a;
    decr Aux1;
end;
while Aux2 not 0 do;
    incr b;
    decr Aux2;
end;

However, the language does not provide < or > operators.

What could I use as a workaround?

2
  • 1
    I see the language has no array. Not even an if statement! I guess that whoever asked you to do this wanted you to work hard to understand the essence of computation. I would suggest you edit your question adding your attempts to the exercise Commented Apr 16, 2010 at 15:14
  • My workflow: 1. retag; 2. read what meta says about it. Meh. Commented Apr 16, 2010 at 15:31

2 Answers 2

5

Oh, come on, start thinking about the problem!

What's an array? A list of variables.

So Barebones doesn't have an if statement? It's got while loops.

Get on with your homework.

Sign up to request clarification or add additional context in comments.

Comments

2

Interesting exercise.

I would suggest you try to first implement the following:

  • Swap values of two variables
  • Set a variable (say z) to zero if value of variable x >= value of variable y.

Since the program is supposed to sort exactly 6 integers, I suppose you can assume they are in the variables x1, x2, .., x6.

In the end we need: x1 <= x2 <= ... <= x6.

2 Comments

to swap the values of 2 variables the code would be along the lines of while a not 0 do; incr Aux1; decr a; end; while b not 0 do; incr Aux2 decr b end; while Aux1 not 0 do; incr a; decr Aux1; end; while Aux2 not 0 do; incr b; decr Aux2; end; however the language provides no implementation of > or < operators and therefore am stuggling to work out how to solve this problem(unless i am missing something stupid)
sorry should'nt have put that above

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.