Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7571359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:39:24+00:00 2026-05-30T15:39:24+00:00

If I were making something like an undo stack, and I wanted to only

  • 0

If I were making something like an undo stack, and I wanted to only support 30 undo operations, it would be nice to have a stack that had a maximum depth of 30.

You obviously wouldn’t want the stack to restrict additions at this point, you would just want it to discard the bottom-most element when a 31st was added.

I’m aware I can mimic this kind of functionality with a list, but I was wondering if there’s a way to make it happen with STL or if there are other pre-implemented options for this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T15:39:26+00:00Added an answer on May 30, 2026 at 3:39 pm

    I would use a circularly-linked list (or just a buffer that you use circularly) with 30 nodes (or elements). You would start of the top and bottom pointers at the same node, and advance the top whenever you added an element and regress it when you remove one. if you add so many elements that you reach the bottom (you have gone all the way around the loop) then you advance the top and the bottom pointer so that they don’t cross each other, and overwrite the one that was under the bottom pointer (where the top pointer now points).

    Another way to do it is to allocate an array (or wrap around a vector) instead of dynamically allocating memory, and modulusing your indices by 30 when you want to advance an index.

    Either way, you never have to allocate or deallocate memory except at the beginning and you can handle overflowing really well. You can read the specifics at the Wikipedia page about circular buffers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was thinking about making something like Linq for Lua, and I have a
Say I am making something like a quiz, and I have a counter to
I'm making a game and would like to have a background loop of game
I'm making something like an augmented reality app, in which I have an OpenGL
I'm making an app that behaves something like the default Messages.app in iPhone where
This problem is making me a bit crazy. I have something like this <h3>Feeds
I'm making a program (think: something like Launchy ) that, more or less, goes
I'm making a Google Maps-like application for a course at my Uni (not something
When making software, specially games, those resources like graphics and sounds are something freaky
is there any possibility to call method just before making object persistent? Something like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.