#include <stdio.h>
#include <stdlib.h>
#define MaxSize 50
typedef int ElemType;
typedef struct
{ ElemType data[MaxSize];
int length;
} SqList;
void CreateList(SqList *&p,ElemType a[],int n) //建立順序表
{
int i;
p=(SqList *)malloc(sizeof(SqList));
for (i=0;i<n;i++)
p->data[i]=a[i];
p->length=n;
}
bool ListEmpty(SqList *p) //判空
{
return(p->length==0);
}
void InitList(SqList *&p){ //初始化
p=(SqList *)malloc(sizeof(SqList));
if (p==NULL)
{
exit(0);
}
p->length=0;
}
void DispList(SqList *p) //輸出
{
int i;
if (ListEmpty(p)) return;
for (i=0;i<p->length;i++)
printf("%d ",p->data[i]);
printf("\n");
}
void Inverse(SqList *p){ //逆序放置
int j;
if(ListEmpty(p)) return;
for(j>(p->length)-1;j>=0;j--)
printf("%d ",p->data[j]);
printf("\n");
}
void DestroyList(SqList *&p) //銷毀線性表
{
free(p);
p=NULL;
}
int main(){
SqList *p=NULL;
InitList(p);
ElemType e;
ElemType a[]={1,2,3,4,5,6,7,8};
CreateList(p,a,8);
DispList(p);
Inverse(p);
DestroyList(p);
return 0;
}
uj5u.com熱心網友回復:
void Inverse(SqList *p){ //逆序放置
int j;
if(ListEmpty(p)) return;
for(j=(p->length)-1;j>=0;j--)
printf("%d ",p->data[j]);
printf("\n");
}
這個函式你把=打成了>
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/15809.html
標籤:基礎類
下一篇:c.語言
