python设计整数顺序表的基本运算程序
时间: 2023-04-12 08:02:10 浏览: 112
可以使用以下代码来设计整数顺序表的基本运算程序:
```
class IntList:
def __init__(self, *args):
self.values = [int(arg) for arg in args]
def __repr__(self):
return str(self.values)
def __len__(self):
return len(self.values)
def __getitem__(self, index):
return self.values[index]
def __setitem__(self, index, value):
self.values[index] = value
def __delitem__(self, index):
del self.values[index]
def append(self, value):
self.values.append(value)
def insert(self, index, value):
self.values.insert(index, value)
def sort(self):
self.values.sort()
def reverse(self):
self.values.reverse()
def pop(self, index=-1):
return self.values.pop(index)
def clear(self):
self.values.clear()
```
这个程序定义了一个名为 IntList 的类,它可以用来创建整数顺序表。这个类包含了一些基本的运算,比如获取元素、设置元素、删除元素、添加元素、排序、反转、弹出元素和清空整个列表。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)