C++ 顺序表创建与遍历:Dev-C++ 实现代码示例
#include <iostream>
using namespace std;
const int MAXSIZE = 100;
typedef struct {
int data[MAXSIZE];
int length;
} SqList;
void InitList(SqList &L) {
L.length = 0;
}
void CreateList(SqList &L) {
cout << '请输入序列长度:';
cin >> L.length;
cout << '请输入序列元素:';
for (int i = 0; i < L.length; i++) {
cin >> L.data[i];
}
}
void TraverseList(SqList L) {
cout << '遍历结果:';
for (int i = 0; i < L.length; i++) {
cout << L.data[i] << ' ';
}
cout << endl;
}
int main() {
SqList L;
InitList(L);
CreateList(L);
TraverseList(L);
return 0;
}
原文地址: https://www.cveoy.top/t/topic/nwmA 著作权归作者所有。请勿转载和采集!