aspose file tools*
The moose likes Beginning Java and the fly likes  stack implementation? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark " stack implementation?" Watch " stack implementation?" New topic
Author

stack implementation?

catherine matthews
Ranch Hand

Joined: Jan 22, 2006
Posts: 78
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

Joined: Feb 07, 2005
Posts: 2367
I believe there is still a Stack class in java.util
catherine matthews
Ranch Hand

Joined: Jan 22, 2006
Posts: 78
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

Joined: Feb 07, 2005
Posts: 2367
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

Joined: Oct 13, 2005
Posts: 36486
    
  16
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

Joined: Jan 30, 2000
Posts: 18671
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 ]

"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: stack implementation?
 
Similar Threads
could someone explain the basics from below attached code
page directive import attribute
JSP string conversion
invoking methods while inside methods
Compile error