Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

help with syntax and backtracking search

syntax

  • Please log in to reply
2 replies to this topic

#1 TigerUppercut

TigerUppercut

    CC Lurker

  • Just Joined
  • Pip
  • 3 posts

Posted 19 February 2007 - 04:07 PM

hello,

for a class I have to take some ugly written code and rewrite it but I have ran into some problems. I'm not too sure how backtracking search and in particular this line is really confusing: o = i==0? 0: s[i-1]; If anybody could explain what's going on in this program and specifically what that line means I would greatly appreciate it. Thank you.
  • 0

#2 TigerUppercut

TigerUppercut

    CC Lurker

  • Just Joined
  • Pip
  • 3 posts

Posted 19 February 2007 - 04:08 PM

oh sorry the source code can be found here: =http://www.soe.ucsc..../raw-sequence.c
thanks again!
  • 0

#3 CyberByte

CyberByte

    CC Lurker

  • Just Joined
  • Pip
  • 5 posts

Posted 21 February 2007 - 04:53 AM

o = i==0? 0: s[i-1];
means:
if (i == 0) {
    o = 0;
} else {
    o = s[i-1];
}

I think it's called the ternary operator and it's used as a shorthand for simple if-else statements.

As for the program: I don't really have a lot of time to look at it right now, and I think it would really help if you would just try translating the program into something more legible. Both for yourself as for other people that might try to help you.
I just looked at it real quick and I think the program is looking for a permutation of the numbers 1 to N, but I'm not sure what the criteria are for what sort of permutation is valid.
  • 0





Also tagged with one or more of these keywords: syntax

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download