DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4

Thread: Stack Program

  1. #1
    Join Date
    Apr 2007
    Posts
    1

    Stack Program

    I have recently been assigned an assignment where I cannot use the stack library and I have to write all the functions for stack (ie. pop, push, empty, etc).
    I have to use a class and an array to keep track of the stack.
    My problem is how can I delete elements in the array? Can you?
    The function "pop" would require me to delete the element at the top of the array, not set it to 0 but delete it. How can this be done?
    Any help would be appreciated (info on the stack library would be cool too).

    Thanks

    Mingk

  2. #2
    Join Date
    Apr 2007
    Location
    Chennai,India
    Posts
    6
    Hi,
    Then you should implement a linked list.
    Initially you can allocate a list of fixed size using calloc and then you can access the elements as getting from an array.

    If this can help you , then i can give you some more info on this
    Thanks
    Raghu

  3. #3
    Join Date
    Jan 2007
    Posts
    145
    Keep a variable called count to keep track of number of entries in the stack.

  4. #4
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    You should be able to find LOTS of info on the web on this topic.

    With a "fixed" array, the bottom of the stack is at element 0 and the top of the stack moves "upward". You don't want to get into the re-sizing of the array so just decrement the pointer for top of the stack; if you are going overboard about it all, over-write the old entry with 0 or null (depending on what you are storing in your stack) as a way to test if the entry is "empty".

    A very nice implementation would be using a "circular array" - use a pointer to the top of the stack, and the bottom element, and the size. Some tricky math to determine whether you are full, but it keeps you within the bounds of the array. To "pop" you just decrement the top of the stack pointer ...

Similar Threads

  1. soft drink Vending machine program
    By divagoddess in forum C++
    Replies: 5
    Last Post: 08-14-2009, 03:12 PM
  2. help, dont know why program is too slow
    By bob2000 in forum Java
    Replies: 1
    Last Post: 02-18-2007, 07:43 PM
  3. Help with this Stack program
    By chief in forum C++
    Replies: 3
    Last Post: 02-22-2006, 04:18 AM
  4. Queue Stack Question
    By trixma in forum Java
    Replies: 4
    Last Post: 08-14-2005, 01:03 PM
  5. Please help with running executable vb program.
    By Gordon Reichhardt in forum VB Classic
    Replies: 2
    Last Post: 01-08-2002, 10:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links