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 6691335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:44:23+00:00 2026-05-26T05:44:23+00:00

So I have this really large method I wrote. If it’s given a stack,

  • 0

So I have this really large method I wrote. If it’s given a stack, it will return a stack. If it’s given a queue, it will return a queue. It uses a lot of recursion, and it accepts a queue/stack and returns that same queue/stack modified accordingly.

I don’t want to copy/paste my method just so I can change the type used inside, so is there any way I can make this generic? As in, it will accept any old collection and play with it? I tried just using Collection, but the trouble with that is it doesn’t have a .remove() I can use with the stack/queue.

Any help would be greatly appreciated.

Thanks.

  • 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-26T05:44:24+00:00Added an answer on May 26, 2026 at 5:44 am

    You could use Collection but then have special case handling just around your remove operations. Of course you’ll have to figure out what to do when you get a collection that’s not one of the two.

    if (myCollection instanceof Queue) {
        ((Queue)myCollection).remove();
    } else if (myCollection instanceof Stack) {
        ((Stack)myCollection).remove(thingy);
    } else {
        // Oops! Now what?
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Really quick jQuery question... I have this function: $(document).ready(function() { $('a#show1').click(function() { $('.item1').toggle(1000); return
this is really frustrating me. this problem occurs when I have a particularly large
So I have this program that I really like, and it doesn't support Applescript.
I have this case <WrapPanel> <CheckBox>Really long name</CheckBox> <CheckBox>Short</CheckBox> <CheckBox>Longer again</CheckBox> <CheckBox>Foo</CheckBox> <Slider MinWidth=200
Ok I have this problem that I've never had before, it's really bugging me.
I have read that you can do it, but would this really improve performance
I have really no idea why I'm asking this as this a really completely
This is really getting to me now.I have a form that loads when the
I have seen this macro defined before but never really knew its purpose. Can
This is really driving me nuts, I have a datagridview bound to a bindingsource,

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.