데이터 구조 -- 순서 표 의 첨삭 검사

30357 단어 필기 하 다.
#include 
#include 
#include 
#include 
#define MAXLEN 100

typedef int DataType;

typedef struct seqlist
{
	DataType Data[MAXLEN];
	int Length;

}SeqList;

SeqList L;


void InitList(SeqList *L)//   
{
	L->Length=0;
}

void CreateList(SeqList *L)//  
{
	int i,n;
	printf("

"
); scanf("%d",&n); printf("
%d
"
,n); for(i=0;i<n;i++) { scanf("%d",&L->Data[i]); } L->Length=i; } void DispList(SeqList *L)// { int i; for(i=0;i<L->Length;i++) printf("%-4d",L->Data[i]); printf("
"
); } int DelList(SeqList *L)// { int n; printf("
"
); scanf("%d",&n); if(L->Length==0) { printf(" ,
"
); return 0; } else if(n<1||n>L->Length) { printf(" ,
"
); return 0; } else { for(n=n-1;n<L->Length;n++) { L->Data[n]=L->Data[n+1]; } L->Length-=1; printf(" ! :
"
); return 1; } } int Lookup1(SeqList *L)// { int i,n,y=0; printf("
"
); scanf("%d",&n); for(i=0;i<L->Length;i++) { if(n==L->Data[i]) y=1; } if(y==0) { printf(" !
"
); return 0; } else { printf(" :"); for(i=0;i<L->Length;i++) { if(n==L->Data[i]) printf(" %d",i+1); } printf("
"
); return 1; } } int Lookup2(SeqList *L)// { int n; printf("
"
); scanf("%d",&n); if(n<1||n>L->Length) { printf(" !
"
); return 0; } if(n <= L->Length) { printf(" :%d
"
,L->Data[n-1]); return 1; } } int Ins(SeqList *L)// { int n,i,num; printf("
"
); scanf("%d",&n); if(n<1||n>L->Length) { printf("
"
); return 0; } if(n <= L->Length) { printf("
"
); scanf("%d",&num); { for(n-=1,i=L->Length;i>n;i--){ L->Data[i]=L->Data[i-1]; } } } L->Data[n]=num; L->Length++; printf(" , :
"
); return 1; } void Menu() { printf("
"
); printf("
=================================="
); printf("
| 1 |"
); printf("
| 2 |"
); printf("
| 3 |"
); printf("
| 4 |"
); printf("
| 5 |"
); printf("
| 6 |"
); printf("
| 0 |"
); printf("
=================================="
); printf("
(0~6):"
); } int main() { int number; char ch='Y'; SeqList L; InitList(&L); // while(ch=='Y'||ch=='y') { Menu(); scanf("%d",&number); getchar(); switch(number) { case 1: CreateList(&L); printf("
"
); DispList(&L); break; case 2: Ins(&L); DispList(&L); break; case 3: DelList(&L); DispList(&L); break; case 4: Lookup2(&L); DispList(&L); break; case 5: Lookup1(&L); DispList(&L); break; case 6: printf(" :%d
"
,L.Length); break; case 0: ch='n'; break; default: printf(" , 0~6 !
"
); } } return 0; }

좋은 웹페이지 즐겨찾기