Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How to sort the integer by not using "array"
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
8749236




PostPosted: Thu Feb 03, 2011 11:31 am   Post subject: How to sort the integer by not using "array"

What is it you are trying to achieve?
Our teacher give us a class assignment, he want us to sort the integers by not using code :"array"

What is the problem you are having?
The only way i know is use the "if" statement. is their any easier way to sort the integers?

Describe what you have tried to solve this problem
i tried "label" but doesn't work well (maybe is my fault..)

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


<Add your code here>



Please specify what version of Turing you are using
Turing 4.1
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Thu Feb 03, 2011 12:35 pm   Post subject: RE:How to sort the integer by not using "array"

I'm not exactly sure what you're asking here. Are you supposed to sort a bunch of given integers? Are you sorting one or two user-inputted integers? Why aren't you to use arrays?
SNIPERDUDE




PostPosted: Thu Feb 03, 2011 4:46 pm   Post subject: RE:How to sort the integer by not using "array"

A full description of the task required would be helpful.
8749236




PostPosted: Thu Feb 03, 2011 8:14 pm   Post subject: RE:How to sort the integer by not using "array"

we are trying to make a program..
the user input a bunch of integer, and our program need to reorganize it from smallest to biggest, but we cannot use the code "array"
Tony




PostPosted: Thu Feb 03, 2011 8:33 pm   Post subject: RE:How to sort the integer by not using "array"

How many integers? What's the range of valid values? Are you supposed to avoid just the keyword of "array" (build in implementation) or the concept of an array (let's say C's pointer + offsets)? Can you store integers in any other data-structure such as lists or trees?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
8749236




PostPosted: Fri Feb 04, 2011 10:30 am   Post subject: RE:How to sort the integer by not using "array"

just avoiding the "array"...
and others have no limit...
Zren




PostPosted: Fri Feb 04, 2011 1:48 pm   Post subject: RE:How to sort the integer by not using "array"

First lets get some questions out of the way.

Do you know what arrays are? It's hard to not use something when you don't even understand what it is.
Is there a maximum amount of numbers (Eg 5 numbers) that you need to sort?
Do you understand the concept of sorting in general? If you had 3 different numbers in 3 different variables, how would you print them to the screen in ascending order (low->high)?
TokenHerbz




PostPosted: Fri Feb 04, 2011 8:06 pm   Post subject: RE:How to sort the integer by not using "array"

why cant i call same named variables differing in numbers 1 .. upper in a for loop to use them???

Turing:


var text1: string := "TEST"
var text : string := ""

for i: 1 .. 1
    %%%WHY CAN'T I CALL VARIABLES LIKE THIS???
    put "TEST" + intstr(i) %% <-- "variable name"                                          :::OUTPUTS TEST1
    put  text + intstr(i) %%how do i call text1 using this type of method?          :::OUTPUTS 1
                     %%%%WANT IT TO OUTPUT ::: "TEST"
end for



I want wanting to just test something but This wont work, and imo it should. but alas turing cant use variables well... Is there a way to use them in this type of set up????

Turing:

var num1 : int := 7
var num2 : int := 3
var num3 : int := 5

loop
    var reset_fors : boolean := false
    var tempsmall, templarge : int := 0
    for i : 1 .. 3
        if reset_fors = true then
            return
        end if
        for j : 1 .. 3
            if reset_fors = true then
                return
            end if
            if num (intstr (i)) > num (intstr (j)) then
                tempsmall := num (intstr (j))
                templarge := num (intstr (i))
                num (intstr (i)) := tempsmall
                num (intstr (j)) := templarge
                reset_fors := true
            end if
        end for
    end for
    exit when reset_fors = false
end loop
put "DONE"
put num1
put num2
put num3

THX
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Fri Feb 04, 2011 9:40 pm   Post subject: RE:How to sort the integer by not using "array"

Why not? Because that's what arrays are for. Duh. This concept is actually called "variable variables" and if used improperly, it's almost impossible to debug. Very few languages support it (those that do include PHP and Ant).

Why aren't you using arrays, again?
huskiesgoaler34




PostPosted: Sat Feb 05, 2011 4:08 pm   Post subject: Re: How to sort the integer by not using "array"

DemonWasp is correct. This would be a perfect time to use arrays. That's what they are supposed to do. I don't understand why your teacher wouldn't allow you to use arrays when arrays are the most efficent way to slove your problem.
TokenHerbz




PostPosted: Sat Feb 05, 2011 7:01 pm   Post subject: RE:How to sort the integer by not using "array"

perhaps they are trying to encourage an recursive type of answer or something, But yeah, arrays rule.

I tried some other ways and well, I'm curious to know why you cant use them either.
DemonWasp




PostPosted: Sat Feb 05, 2011 7:26 pm   Post subject: RE:How to sort the integer by not using "array"

I mean, it's certainly possible to sort things in non-array objects, such as lists and trees. However, it seems unlikely that a course at that level would be writing in Turing.
huskiesgoaler34




PostPosted: Sat Feb 05, 2011 8:45 pm   Post subject: Re: How to sort the integer by not using "array"

The author of the thread wrote that he thought of an if statement. An if statement is used only for conditions. If somethings happens then do this, etc. Label won't work very well for this program.
huskiesgoaler34




PostPosted: Sat Feb 05, 2011 8:53 pm   Post subject: Re: RE:How to sort the integer by not using "array"

Turing:

var num1 : int := 7
var num2 : int := 3
var num3 : int := 5

loop
    var reset_fors : boolean := false
    var tempsmall, templarge : int := 0
    for i : 1 .. 3
        if reset_fors = true then
            return
        end if
        for j : 1 .. 3
            if reset_fors = true then
                return
            end if
            if num (intstr (i)) > num (intstr (j)) then
                tempsmall := num (intstr (j))
                templarge := num (intstr (i))
                num (intstr (i)) := tempsmall
                num (intstr (j)) := templarge
                reset_fors := true
            end if
        end for
    end for
    exit when reset_fors = false
end loop
put "DONE"
put num1
put num2
put num3

THX[/quote]

This program doesn't work. The variable num hasn't been declared nor has it been set a value.
Insectoid




PostPosted: Sat Feb 05, 2011 8:57 pm   Post subject: Re: RE:How to sort the integer by not using "array"

huskiesgoaler34 @ Sat Feb 05, 2011 8:53 pm wrote:
Turing:

var num1 : int := 7
var num2 : int := 3
var num3 : int := 5

loop
    var reset_fors : boolean := false
    var tempsmall, templarge : int := 0
    for i : 1 .. 3
        if reset_fors = true then
            return
        end if
        for j : 1 .. 3
            if reset_fors = true then
                return
            end if
            if num (intstr (i)) > num (intstr (j)) then
                tempsmall := num (intstr (j))
                templarge := num (intstr (i))
                num (intstr (i)) := tempsmall
                num (intstr (j)) := templarge
                reset_fors := true
            end if
        end for
    end for
    exit when reset_fors = false
end loop
put "DONE"
put num1
put num2
put num3

THX


This program doesn't work. The variable num hasn't been decalred nor has it been set a value.[/quote]

If you'd care to read the entire post containing this code segment you'd see the author already knew it wouldn't work. Yeah, this can be done using conditions if you know EXACTLY how many numbers you're inputting but if it's a variable quantity then it's probably impossible in Turing.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 21 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: