• Post Reply Bookmark Topic Watch Topic
  • New Topic

Searching a stack  RSS feed

 
natsumi jay
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to find the location of the String in the stack from the bottom.
So if I push ted, ted1, and ted2.
If I search ted2, the program should return 2.
or -1 if not found at all.


My reverse looks like
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you trying to search a stack in the first place? The idea of a stack is that it has a head reference and the remainder. (Any of those might be null.)
 
natsumi jay
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Part of a project..
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IMHO, something needs to be re-designed then. Stacks aren't supposed to be searched. It's like saying "I want to know how to use a hammer to tighten a screw". Sure, you probably CAN get it to work, but perhaps there is a better tool you could be using.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!