Thread: Stack Based Array?

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    5

    Post Stack Based Array?

    Hey all,

    I've got an assignment due soon, and my teacher gave us an ok to use outside sources. It's on stack-based arrays... Here's the actual assignment, as it is written.

    I can use some pointers/tips/whatever you can offer.

    The assignment will be attached.

    If you can help, cool. If you don't want to help... offer me a tip?
    Last edited by suckerpunch678; 03-29-2005 at 03:01 PM.

  2. #2
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    715
    Quote Originally Posted by suckerpunch678
    Hey all,

    I've got an assignment due soon, and my teacher gave us an ok to use outside sources. It's on stack-based arrays... Here's the actual assignment, as it is written.

    I can use some pointers/tips/whatever you can offer.

    The assignment will be attached.

    If you can help, cool. If you don't want to help... offer me a tip?
    That's really great, we're going to help you, but only after you help yourself. Just show us what you manage to do and where you get stucked. and we'll solve it together. Otherwise read this:
    http://cboard.cprogramming.com/annou...ouncementid=39
    Last edited by Micko; 03-29-2005 at 04:07 PM.
    Gotta love the "please fix this for me, but I'm not going to tell you which functions we're allowed to use" posts.
    It's like teaching people to walk by first breaking their legs - muppet teachers! - Salem

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    5
    Quote Originally Posted by Micko
    That's really great, we're going to help you, but only after you help yourself. Just show us what you manage to do and weher you get stucked. and we'll solve it together. Otherwise read this:
    http://cboard.cprogramming.com/annou...ouncementid=39
    I'm not asking for anyone to do the assignment...

    how about some pseudocode to get me started?

    *Assignment attached

    Thanks

  4. #4
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    how about some pseudocode to get me started?

    Erm how about some pseudocode from you and then we can start helping? This is how these forums operate.

    Nobody will do your homework for you unless, of course they want their own reputation to go down. As I found out to my horror! lol

    However, helping someone once they have their own code is Ok.
    Moreover, it prevents ppl like you from blindly copying other ppl's code and trying to fob it off as your own- and then getting into very hot water when the examiners realise it ain't yours.


    Code:
    {a(<b+[c]>)}  Why is this legal
    
    
    {a[b+(c+d])}  And not this?

    hmmm, I can see it, can you?

  5. #5
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    715
    Well, for start array based stack is somethink like this:
    Code:
    char stack[N]; //where N is compile time constant
    int i = 0;
    //push on the stack 
    stack[i++];
    //pop from the stack
    stack[--i];
    Algorithm coud be something like this.
    Get string from user. Go from the begining of the string and if character is {,[,( or < then push to stack, if character is any other character ignore. While traversing string from the begining to the end check for characters },], ) or >. For example If you find } then pop character from the stack and chack if it is a coresponding character (in this case we check if pop will return left brace}) If not then expression is not correct, otherwise continue with sam procedure until stack is empty.
    Example {A{B<C>(E)F}(G)}
    push { => stack: {
    ignore A
    push B => stack: { {
    ignore B
    push < => stack: { { <
    ignore C
    found > => pop from he stack, compare pop value with current value, it's ok so continue => stack: {{
    push (

    ... etc
    That's it I'm waiting to see what you're going to do!!!
    Last edited by Micko; 03-29-2005 at 04:30 PM.
    Gotta love the "please fix this for me, but I'm not going to tell you which functions we're allowed to use" posts.
    It's like teaching people to walk by first breaking their legs - muppet teachers! - Salem

  6. #6
    Registered User
    Join Date
    Mar 2005
    Posts
    5
    Okok.. I put together a program that should work when it is compiled, but I can't get past the syntax errors.

    Can you help me out with them?

    It's attached, and should be well documented. Thanks.

  7. #7
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    I've got an assignment due soon, and my teacher gave us an ok to use outside sources.
    Hmmmm. So, you can just hire a programmer to write your programs?

  8. #8
    Registered User
    Join Date
    Mar 2005
    Posts
    5
    Quote Originally Posted by 7stud
    Hmmmm. So, you can just hire a programmer to write your programs?
    It's my work; I'm just asking for help. If you can and are willing, please do so... otherwise..

  9. #9
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    i think i'm going to start writing really good, solid, advanced, complex, and unnecessary code for people to turn in as homework .......and then commenting it very poorly - and by poorly i mean putting BS comments in - might even try to sneak in a "//someone else did this entire project"
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  10. #10
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    Ok you probably want to read up on 'vectors' since they tie in with the idea of stacks (pushing and popping). If you go to FAQ and look under ' Preludes' corner this should get you started.

    Otherwise, you can always google for vectors.

    In terms of the solution- 'Micko' has more or less given it to you on a plate. Read his thread again and try to come up with a flow chart. Once you've done that, read up on vectors. Ok, all new stuff takes some time to get to grips with but it's worthwhile in the end!

    Dem be useful little things -vectors.

    Good luck

  11. #11
    Registered User
    Join Date
    Mar 2005
    Posts
    5
    I got the program to compile and work. Thanks to all who offered assistance... and to you others..

    The final product is attached.

  12. #12
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    715
    Not bad you're making progress...
    Just one thing, what if user enter something like this:
    Code:
    [sd      (fdsf)          ]
    What will happen then??
    And why??
    Think about it a little!
    Gotta love the "please fix this for me, but I'm not going to tell you which functions we're allowed to use" posts.
    It's like teaching people to walk by first breaking their legs - muppet teachers! - Salem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 01:01 AM
  2. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 12:09 PM
  3. Array Program
    By emmx in forum C Programming
    Replies: 3
    Last Post: 08-31-2003, 12:44 AM
  4. Stack functions as arrays instead of node pointers
    By sballew in forum C Programming
    Replies: 8
    Last Post: 12-04-2001, 11:13 AM
  5. Stack Program Here
    By Troll_King in forum C Programming
    Replies: 7
    Last Post: 10-15-2001, 05:36 PM