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

  • Home
  • SEARCH
  • 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 6569925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:41:30+00:00 2026-05-25T14:41:30+00:00

I have a project to create a circular array class, and the language I

  • 0

I have a project to create a circular array class, and the language I will be using is python. I am new to classes in python, but after reading through some webpages and chapters in books I think I have an understanding of how they work. However I need help, so I figured I would come to the wonderful teachers here at SO 🙂

Our class must be able to implement several operations; insert at front, insert at back, insert at index, remove from front, remove from back, remove from index.

I have started coding but am running into some problems, and I am not 100% sure if my syntax is even right.

Here is what I have so far:

class circular:

    def __init__(self):
        self.store = []
        self.capacity = len(self.store)
        self.size = 0
        self.startIndex = 0
        self.endIndex = 0

    def decrementIndex(self):
        index = index - 1
        if index < 0:
            self.store = self.store + self.capacity

    def incrementIndex(self):
        index = index + 1
        if index == self.capacity:
            index = index - self.capacity

    def addToBack(self, value):
        self.store[self.endIndex] = value
        self.endIndex = incrementIndex(self.endIndex)
        self.size += 1

    def addToFront(self, value):
        if self.size == 0:
            addToBack(self, value)
        else:
            self.startIndex = decrementIndex(self.startIndex)
            self.store[self.startIndex] = value
            self.size += 1

I stopped there to start testing some of the functions, primarily t he addTofront and addToback. Upon testing them in IDLE using c = circular() and c.addToBack(2) I get an index error…and I’m not sure why. That isn’t the only problem, it’s just where I have gotten stuck and need help moving forward.

I am posting here because I need help and want to learn, not because I am lazy and haven’t tried researching my problem. Thanks already SO!

  • 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-25T14:41:30+00:00Added an answer on May 25, 2026 at 2:41 pm

    In __init__ you set

    self.store = []
    

    In addToBack you do

    self.store[self.endIndex] = value
    

    If this is the first operation on the circular array, and you pass 2 as the value, then that turns into

    [][0] = 2
    

    The problem should be obvious — an empty list has no index of 0, it has no indexes at all.

    You need to add the item to the list in a different way.

    I’m not going to tell you exactly how as it’s part of your homework to figure that out.

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

Sidebar

Related Questions

So for my programming class we have had a project to create a virtual
I have a project to create a program, which prevents the user from escaping
I have a project where I create WiX (Windows Installer for XML) files, when
If you create an ASP.NET web file project you have direct access to the
We have a netbeans project that has an xsd that we use to create
I have a maven project and I'd like to create a distribution of it
I am working on a project and have the following psuedocode: // create a
I have a RoR project on my Windows 7 PC. I want to create
I have the following code. <s:push value=#session['person']> <s:if test=%{admin=='y'}> <a class=add href=/projit1/project/addProject.jsp>Create a Project</a>
For some reason, my visual studio 2008 installation doesn't have the Create Test Project

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.