Thread: algorithm for stack

  1. #1
    Registered User
    Join Date
    Jul 2014
    Posts
    3

    Question algorithm for stack

    write an algorithm using stack to determine if an input of string is in the form xCy where y is the reverse of x.x and y are strings of A and B.
    eg AABACABAA

    please help me out!

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    What are you having a problem with? You should post any code you're having trouble with (in code tags) and ask specific questions about where you're stuck.

  3. #3
    Registered User
    Join Date
    Jul 2014
    Posts
    3
    I want the algorithm.I have no idea how to go about!!I have to submit this assignment by monday .If you or anyone can give me the the algorithm i would be saved .

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    write an algorithm using stack to determine if an input of string is in the form xCy where y is the reverse of x.x and y are strings of A and B.
    If you or anyone can give me the the algorithm i would be saved .
    Not likely going to happen - we have a homework policy here.

    Since this is an assignment, it stands to reasons that you've learned something about this problem (or something that can be used for solving it) during class. For instance, have you worked with stacks yet?

    Think about it, come up with some ideas, and ask questions about those ideas if you're uncertain.

    But don't expect a hand-out.

  5. #5
    Registered User
    Join Date
    Jul 2014
    Posts
    3
    No I have not worked with stack ever before.Its ok.whatever.

  6. #6
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Since that's required for the assignment, it seems like a good place to start: Stack (abstract data type) - Wikipedia, the free encyclopedia

  7. #7
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    There is virtually nothing more to the algorithms for stack operations than their description.
    Simply read what the stack operations do and implement that.
    Do not expect anyone here to write code for you.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Since a stack only has two operations - push and pop, there isn't really much to figure out.

    > eg AABACABAA
    Or
    A - push or pop - you decide. Well since you haven't done anything yet, the only real choice is push
    A - push or pop - try both (on paper)
    B - and so on....
    A
    C
    A
    B
    A
    A
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User zub's Avatar
    Join Date
    May 2014
    Location
    Russia
    Posts
    104
    Stack can be represented as an infinite array and the index of the empty element. In order to push the letter we put it into an array and increment the index. For popping just decrease index and get element by it.
    Our goals are clear, tasks are defined! Let's work, comrades! -- Nikita Khrushchev

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. stack
    By CASHOUT in forum C++ Programming
    Replies: 4
    Last Post: 07-14-2013, 02:02 PM
  2. Recursive Stack Algorithm Maze Solver
    By unrestricted in forum C Programming
    Replies: 0
    Last Post: 09-04-2007, 03:11 AM
  3. STL Stack Example
    By smitsky in forum C++ Programming
    Replies: 1
    Last Post: 11-03-2004, 05:07 PM
  4. help with stack
    By razoblade in forum C Programming
    Replies: 1
    Last Post: 02-25-2002, 08:13 AM
  5. my grandfather's chess algorithm can beat your grandfather's chess algorithm...
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 22
    Last Post: 08-17-2001, 06:52 PM