提交 3c86399f 创建 作者: 宋海霞's avatar 宋海霞

modify

上级 f916ceb4
#ifndef LINEARLIST_H_ #ifndef LINEARLIST_H_
#define LINEARLIST_H_ #define LINEARLIST_H_
// //
// Include the C standard library header file here // Include the C standard library header file here
// //
#include <stdio.h> #include <stdio.h>
// //
// Other header files are included here // Other header files are included here
// //
// //
// Define the data structure here // Define the data structure here
// //
...@@ -24,9 +19,13 @@ ...@@ -24,9 +19,13 @@
typedef int ElemType; // The types of elements in a linear table typedef int ElemType; // The types of elements in a linear table
typedef struct { typedef struct SqListElem
ElemType Elements[MAX_LENGTH]; // An array is used to store elements in a linear table whose maximum length is the length of the array. {
int nLength; // The actual length of the linear table, the number of elements in the linear table. // An array is used to store elements in a linear table
// whose maximum length is the length of the array.
ElemType Elements[MAX_LENGTH];
// The actual length of the linear table, the number of elements in the linear table.
int nLength;
}SqList; }SqList;
......
#include "LinearList.h" #include "LinearList.h"
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
SqList List; SqList List;
...@@ -11,8 +10,10 @@ int main(int argc, char* argv[]) ...@@ -11,8 +10,10 @@ int main(int argc, char* argv[])
// Initialize the linear table // Initialize the linear table
// //
List.nLength = 8; List.nLength = 8;
for(i=0; i<List.nLength; i++) for (i=0; i<List.nLength; i++)
{
List.Elements[i] = i; List.Elements[i] = i;
}
// //
// Insert the element after the ith element // Insert the element after the ith element
...@@ -20,7 +21,7 @@ int main(int argc, char* argv[]) ...@@ -20,7 +21,7 @@ int main(int argc, char* argv[])
InsertAfter(&List, 33, 5); InsertAfter(&List, 33, 5);
InsertAfter(&List, 45, 15); // Invalid insert position. Insert failed. InsertAfter(&List, 45, 15); // Invalid insert position. Insert failed.
for(i=0; i<List.nLength; i++) for (i=0; i<List.nLength; i++)
{ {
printf("%d ", List.Elements[i]); printf("%d ", List.Elements[i]);
} }
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论