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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:55:30+00:00 2026-05-20T01:55:30+00:00

sorry, just following on from the question I had here : here I am

  • 0

sorry, just following on from the question I had here : here I am trying to run this method to remove a generic value (EltType) from a double sided queue(deque), but I keep getting an error in that, I call insertFirst twice, and insert the value “3” into the array twice, then, when I run removeFirst, it will print out “3” once, and then “Null” thereafter. Would anyone be able to help me out please ?

class ArrayBasedDeque<EltType> {

  private final int CAPACITY = 10;
  private int capacity;
  private int end;
  private EltType deque[];  

  public ArrayBasedDeque() {
    this.capacity = CAPACITY;
    deque = (EltType[]) (new Object[capacity]);  
  } 


 public EltType removeFirst() {
    EltType[] tempArray;
    EltType returned = deque[0];
    tempArray = (EltType[]) new Object[capacity];
      for (int i=1;i<capacity;i++) {
        tempArray[i-1] = deque[i]; 
      }
      deque = tempArray;
    return returned;
  }


  public boolean isEmpty() {
    return end == 0;
  }

  public void insertFirst(EltType first) {
    if(!isEmpty()) {
    EltType[] tempArray;
    tempArray = (EltType[]) new Object[capacity+1];
    for (int i=0;i<deque.length;i++) {
      tempArray[i+1] = deque[i]; 
    }
    deque = tempArray; 
    }
   deque[0] = first;
  }

}

Thank you 🙂

  • 1 1 Answer
  • 1 View
  • 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-20T01:55:30+00:00Added an answer on May 20, 2026 at 1:55 am

    The big glaring issue is that end never changes. isEmpty() will always return true. Now let’s look at your insertFirst() method.

    public void insertFirst(EltType first) {
        if(!isEmpty()) {
            EltType[] tempArray;
            tempArray = (EltType[]) new Object[capacity+1];
            for (int i=0;i<deque.length;i++) {
                tempArray[i+1] = deque[i]; 
            }
    
            deque = tempArray; 
        } 
        deque[0] = first;
    }
    

    Knowing that isEmpty() always returns true no matter what, what is the problem with this piece of code?

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

Sidebar

Related Questions

Sorry, this might be a basic/stupid/noob question - I am just trying to tweak
sorry for this newb question, i just started programming with php I'm following Yahoo
sorry - I know this is dead easy stuff, but I'm just trying to
Sorry if this is a simple question, but I just can't figure out what
Sorry for turning to here for such a basic question, but can someone just
Just a syntax question, here is my code snippet. (Sorry, browser isn't letting me
Sorry, if this is a noobish question, but I'm just getting started with Rails
Sorry if this is dumb but I was just thinking I should give a
Sorry. I'm just bitten (or bit. Go figure with this left-to-right language :-) I've
Sorry for my bad English. Just like what I asked. I have this class

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.