From: BobPalin on 21 Sep 2009 12:23 What we have to do is take one of our programs that we already turned in and make it use recursion. This program detects if a user entered word is a palindrome. Below is the code for the original program but we're stuck on how to do it using recursion. The part we need to change to recursion is commented out. Thanks!! .data str1: .asciiz "Type a string to see if it is a palindrome: " str2: .asciiz "The string " str3: .asciiz " is a palindrome." str4: .asciiz " is not a palindrome." cr: .asciiz "\n" space: .space 10 .text .globl main main: li $v0, 4 la $a0, str1 syscall li $v0, 4 la $a0, cr syscall li $a1, 10 la $a0, space li $v0, 8 syscall la $t1, space la $t2, space findLen:lb $t3, 0($t2) beq $t3, $zero, endLen add $t2, $t2, 1 j findLen endLen: sub $t2, $t2, 2 ##THIS PART NEEDS CHANGED TO RECURSION************************ #test: bge $t1, $t2, palin # lb $t3, 0($t1) # lb $t4, 0($t2) # bne $t3, $t4, notPalin # addi $t1, $t1, 1 # sub $t2, $t2, 1 # j test #************************************************************************************* palin: la $a0, str2 li $v0, 4 syscall la $t4, space move $a0, $t4 li $v0, 4 syscall addi $t4, $t4, 1 la $a0, str3 li $v0, 4 syscall j done notPalin: la $a0, str2 li $v0, 4 syscall la $t4, space move $a0, $t4 li $v0, 4 syscall la $a0, str4 li $v0, 4 syscall done: li $v0, 10 syscall
From: rossum on 21 Sep 2009 13:03 On Mon, 21 Sep 2009 09:23:05 -0700 (PDT), BobPalin <bowlingbible2(a)yahoo.com> wrote: >What we have to do is take one of our programs that we already turned >in and make it use recursion. This program detects if a user entered >word is a palindrome. Below is the code for the original program but >we're stuck on how to do it using recursion. The part we need to >change to recursion is commented out. Thanks!! 1. A string "ABCDEFG" is a palindrome iff A = G and BCDEF is a palindrome. 2. "A" is a palindrome for all A. 3. "" is a palindrome. rossum
From: BobPalin on 21 Sep 2009 14:38 On Sep 21, 1:03 pm, rossum <rossu...(a)coldmail.com> wrote: > On Mon, 21 Sep 2009 09:23:05 -0700 (PDT), BobPalin > > <bowlingbib...(a)yahoo.com> wrote: > >What we have to do is take one of our programs that we already turned > >in and make it use recursion. This program detects if a user entered > >word is a palindrome. Below is the code for the original program but > >we're stuck on how to do it using recursion. The part we need to > >change to recursion is commented out. Thanks!! > > 1. A string "ABCDEFG" is a palindrome iff A = G and BCDEF is a > palindrome. > > 2. "A" is a palindrome for all A. > > 3. "" is a palindrome. > > rossum Sorry, it appears that I wasn't clear enough with my question. The program above tests to see if what the user inputted is a palindrome. What I need the program to do is the same thing, but recursively. The commented out area needs to be done using recursion. Any suggestions?
From: Richard Heathfield on 21 Sep 2009 16:25 In <f1d4c94c-5296-468d-bb00-e1d4a756cff6(a)l34g2000vba.googlegroups.com>, BobPalin wrote: > On Sep 21, 1:03 pm, rossum <rossu...(a)coldmail.com> wrote: >> On Mon, 21 Sep 2009 09:23:05 -0700 (PDT), BobPalin >> >> <bowlingbib...(a)yahoo.com> wrote: >> >What we have to do is take one of our programs that we already >> >turned in and make it use recursion. This program detects if a >> >user entered word is a palindrome. Below is the code for the >> >original program but we're stuck on how to do it using recursion. >> >The part we need to change to recursion is commented out. >> >Thanks!! >> >> 1. A string "ABCDEFG" is a palindrome iff A = G and BCDEF is a >> palindrome. >> >> 2. "A" is a palindrome for all A. >> >> 3. "" is a palindrome. >> >> rossum > > Sorry, it appears that I wasn't clear enough with my question. The > program above tests to see if what the user inputted is a > palindrome. What I need the program to do is the same thing, but > recursively. Your question was clear enough, and I think you'll find that the answer is clear enough too, if you read it a little more closely. The above is a design for a recursive palindrome algorithm, which rossum provided in an attempt to give you a hint without actually doing the work for you (because that's *your* job). -- Richard Heathfield <http://www.cpax.org.uk> Email: -http://www. +rjh@ "Usenet is a strange place" - dmr 29 July 1999 Sig line vacant - apply within
From: rossum on 21 Sep 2009 16:20 On Mon, 21 Sep 2009 11:38:53 -0700 (PDT), BobPalin <bowlingbible2(a)yahoo.com> wrote: >On Sep 21, 1:03 pm, rossum <rossu...(a)coldmail.com> wrote: >> On Mon, 21 Sep 2009 09:23:05 -0700 (PDT), BobPalin >> >> <bowlingbib...(a)yahoo.com> wrote: >> >What we have to do is take one of our programs that we already turned >> >in and make it use recursion. This program detects if a user entered >> >word is a palindrome. Below is the code for the original program but >> >we're stuck on how to do it using recursion. The part we need to >> >change to recursion is commented out. Thanks!! >> >> 1. A string "ABCDEFG" is a palindrome iff A = G and BCDEF is a >> palindrome. Here "iff" means "if and only if" and A ... G are character variables. >> >> 2. "A" is a palindrome for all A. >> >> 3. "" is a palindrome. >> >> rossum > >Sorry, it appears that I wasn't clear enough with my question. Your question was perfectly clear. You want us to help you with your homework. >The program above tests to see if what the user inputted is a palindrome. >What I need the program to do is the same thing, but recursively. The >commented out area needs to be done using recursion. Any suggestions? My comments should help you to redesign your program so that it works recursively. We do not do your homework for you, but we do offer help. It is up to you to use that help. If you want me to code your progam for you then my rates go up to GBP 200 per hour. Hint: recursion is self-reference. Look for some self-reference in my three points. rossum
|
Next
|
Last
Pages: 1 2 Prev: Function address vs. pointer to member function Next: Python 1 , Lisp 0 |