Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

stack implementation?

 
catherine matthews
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi... i need help in stack.... what i am trying to do is getting an opening curly brace and find the corresponding closing curly braces... so that i can get the cyclometic complexity within a method...Can i implement this using stack? if so how can i use the LinkedList to do this? is there any other simpler way of doing this?
please help me...
[ May 24, 2006: Message edited by: catherine matthews ]
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe there is still a Stack class in java.util
 
catherine matthews
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but my problem is that.... i dont know how to implement it...how do i do find the corresponding curly braces.... within a method there can be many curly braces right.... how do i find which one correponds to which one? how do i use stack for this problem
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the main thing to remember there is that every { has to match up with a } if it's well-formed.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50258
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can make your own Stack, but as people say, yes there is still a java.util.Stack class, available for everybody to use.
Deitel and Deitel's book has an exercise in whereby you can make your own stack.

What have {} got to do with a Stack? I don't understand that part of the question.

CR
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I gather the idea is to parse some code, and you end up using a stack while doing that. For something like this, an algorithm might be:

Here, the things being pushed and popped off the stack are simply integers - in Java using a Stack or other Collection, you're probably using Integer objects. It's also possible you might be pushing and popping some more complex structure, a class containing information representing a syntax structure of some kind. There are many ways to do this depending on how much detail you want or need to get into. I would recommend just using integers initially, until you have a good handle on how this works. Then you can consider modifications to add functionality if necessary.
[ May 24, 2006: Message edited by: Jim Yingst ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic