编写一个程序,输出在顺序表(3,6,2,10,1,8,5,7,4,9)
时间: 2023-12-05 12:40:13 浏览: 82
以下是Python代码,用于输出给定顺序表的内容:
```python
seq_list = [3, 6, 2, 10, 1, 8, 5, 7, 4, 9]
print(seq_list)
```
输出结果为:
```
[3, 6, 2, 10, 1, 8, 5, 7, 4, 9]
```
以下是Python代码,用于输出给定顺序表的长度:
```python
seq_list = [3, 6, 2, 10, 1, 8, 5, 7, 4, 9]
print(len(seq_list))
```
输出结果为:
```
10
```
以下是Python代码,用于在给定位置i插入一个值为x的结点:
```python
seq_list = [3, 6, 2, 10, 1, 8, 5, 7, 4, 9]
i = 2
x = 100
seq_list.insert(i, x)
print(seq_list)
```
输出结果为:
```
[3, 6, 100, 2, 10, 1, 8, 5, 7, 4, 9]
```
以下是Python代码,用于在顺序表中删除值为x的结点或者删除给定位置i的结点:
```python
seq_list = [3, 6, 2, 10, 1, 8, 5, 7, 4, 9]
x = 5
seq_list.remove(x) # 删除值为x的结点
print(seq_list)
i = 2
seq_list.pop(i) # 删除给定位置i的结点
print(seq_list)
```
输出结果为:
```
[3, 6, 2, 10, 1, 8, 7, 4, 9]
[3, 6, 10, 1, 8, 7, 4, 9]
```
以下是Python代码,用于将顺序表逆置,将结果保存到另外的顺序表中:
```python
seq_list = [3, 6, 2, 10, 1, 8, 5, 7, 4, 9]
new_seq_list = seq_list[::-1]
print(new_seq_list)
```
输出结果为:
```
[9, 4, 7, 5, 8, 1, 10, 2, 6, 3]
```
阅读全文