我有一个计划,设立一个循环阵列组,我将使用的语文是假借。 我是新上课的,但经过一些网页和书籍章节的阅读,我认为我了解他们的工作方式。 然而,我需要帮助,因此,我会在这里谈谈在SO:
我们的班子必须能够执行几项行动;在前面插入,在指数上插入,从前线删除,从后撤,从指数中删除。
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.
我在座,是因为我需要帮助和希望学习,而不是因为我是抱歉,没有尝试研究我的问题。 感谢大家!