实验一
代码:
#include \#include
const int nMaxSize = 15; // 最大值 int nLen = 0; // 表中元素个数 int nLinearList[nMaxSize];
// 定义操作 void LSort(); void LOut();
void LInsert(int n); void LDelete(int n); void main() {
// 输入数据并放入线性表中
printf(\// std::cout << \ int nIn = 0;
for (int i = 0; i <= 9; i++) { scanf(\// std::cin >> nIn; nLinearList[i] = nIn; nLen++; }
LSort(); // 排序线性表 LOut(); // 输出结果
printf(\ scanf(\
LInsert(nIn); // 输入一个数字,并插入到线性表中 LOut(); LSort();
printf(\ LOut(); while(1) {
printf(\ scanf(\
if (nIn>nLen)
printf(\
else break; }
LDelete(nIn); // 输入一个数字,并从线性表中删除 LOut();
char chTmp;
printf(\ chTmp = getch(); }
void LSort() // 冒泡排序,由大到小 {
int i,j,temp;
for (j=0;j for (i=0;i if (nLinearList[i] void LOut() { printf( \ for (int i = 0; i <= nLen; i++) { printf( \ } printf( \} void LInsert(int k) { int i,j; while(1) { printf(\:\ scanf(\ if (j>nLen) printf(\ else break; } for(i = nLen; i >= j ; --i) nLinearList[i] =nLinearList[i - 1]; nLinearList[j-1] = k; nLen++; } void LDelete(int m) { int i; for(i = m; i <= nLen; ++i) nLinearList[i-1] = nLinearList[i]; nLen--; } 实验二 代码: #include