数据结构线性表的构建
创建名为线性表的空项目,在创建的线性表中创建线性表cpp文件,之际按c文件的格式写代码即可。
首先要在开头添加两个头文件:
#include <conio.h> (不然,getch()没有定义)
#include <windows.h>
然后,因为clrscr()在vs中没有提供,所以我们采用以下代码来说明,需要与#include <windows.h>相联系使用,添加的代码如下:
void gotoxy(int a, int b){
HANDLE hout;
COORD coord;
coord.X=a;
coord.Y=b;
hout=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hout,coord);
}
void clrscr(){
system(“cls”);
}
然后,开始按数据结构的要求书写代码,具体代码如下所示:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
void gotoxy(int a, int b){
HANDLE hout;
COORD coord;
coord.X=a;
coord.Y=b;
hout=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hout,coord);
}
void clrscr(){
system("cls");
}
/*定义*/ #define ListSize 100
typedef struct
{
int data[ListSize]; /*存放表结点*/
int length; /*表长度*/
}
SeqList;
void main(