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

Username:   Password: 
 RegisterRegister   
 stacks and invariants
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
raptors892004




PostPosted: Tue Dec 19, 2006 9:54 pm   Post subject: stacks and invariants

In the info i got from a slideshow it says:

slideshow wrote:

the link member in the bottom (last) node of the stack is set to null to indicate the bottom of the stack


From searching on the wikipedia website:
wikipedia wrote:
record Node {
data // The data being stored in the node
next // A reference to the next node; null for last node
}


,and before that comparing to a linked list, I think it should be that the pointer to the next node of that last (bottom) node is set to null, right? Or am I wrong? Very Happy

My other question is what are invariants and what are they used for? I hope you respond by tmr because I gotta know this before the quiz because it wasn't explained very well in the provided information.

Thanks for any replies in advance.
Sponsor
Sponsor
Sponsor
sponsor
OneOffDriveByPoster




PostPosted: Tue Dec 19, 2006 11:23 pm   Post subject: Re: stacks and invariants

Quote:
,and before that comparing to a linked list, I think it should be that the pointer to the next node of that last (bottom) node is set to null, right? Or am I wrong? :D

Sounds right. The slideshow said as much though (okay, maybe you had a stack of pointers...).

Quote:
My other question is what are invariants and what are they used for?

Invariants are things that do not change (where they are invariant). You could use them in assertions to check things.

There are other things you could do with them (any more specific ways to describe an invariant), but I think you need to give more info. Any links to the information you got?
raptors892004




PostPosted: Tue Dec 19, 2006 11:42 pm   Post subject: (No subject)

I had some info on loop invariants and four steps to develop a loop from a loop invariant which didn't seem to connect very much (except step 4) to the loop invariant concept i think, but oh well..

4 ways to develop a loop from a loop invariant wrote:
1.Set initial values for any loop control variables.
2. Determine the condition that causes the loop to terminate.
3. Modify the control variable(s) so the loop progresses toward termination.
4. Check that the invariant remains true at the end of each iteration.


Another thing the slideshow said is that invariants should be used to test programs thoroughly.
OneOffDriveByPoster




PostPosted: Wed Dec 20, 2006 9:06 am   Post subject: (No subject)

raptors892004 wrote:
... four steps to develop a loop from a loop invariant...

Interesting. So you are saying that given a loop invariant, you want to develop/implement a loop that satifies the invariant?

Quote:
1.Set initial values for any loop control variables.
2. Determine the condition that causes the loop to terminate.
3. Modify the control variable(s) so the loop progresses toward termination.
4. Check that the invariant remains true at the end of each iteration.

Assuming a response in the affirmative to the above question, these steps are probably okay--but they are less steps, but more things you have to consider. In fact, you need the first three for practically any loop.

"Step 4" is actually much more than it can appear to be. The key could be to consider what side-effects the loop should have (if any) such that the invariant will be true at the end of each iteration. (As far as I know, it should also be true going into the loop--that is, true before the loop starts).

Quote:
Another thing the slideshow said is that invariants should be used to test programs thoroughly.

That is where the bit about the "assertions" comes from in my previous response.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: