• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

stack implementation?

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic