天天看點

全網最詳細王道考研大題,c語言詳解

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MaxSize 50
typedef int ElemType ;
//定義順序表
typedef struct{
    ElemType data[MaxSize];
    int length;
}SqList;
//定義單連結清單
typedef struct LNode{
    ElemType data;
    struct LNode *next;
}LNode,*LinkList;
//定義雙連結清單
typedef struct DNode{
    ElemType data;
    struct DNode *next,*prior;
}DNode,*DLinkList;
//初始化順序表
void InitList(SqList &L){
    for(int i=0;i<MaxSize;i++){
        L.data[i]=0;
    }
    L.length=0;
}
//列印單連結清單
void printList(LinkList L){
    LNode *p=L->next;
    while(p!=NULL){
        printf("%d\t",p->data);
        p=p->next;
    }
    printf("\n");
}
//列印雙連結清單
void printDList(DLinkList L){
    DNode *p=L->next;
    while(p!=L){
        printf("%d\t",p->data);
        p=p->next;
    }
    printf("\n");
}
//計算長度
int length(LinkList L){
    LNode *p=L->next;
         

繼續閱讀