天天看点

全网最详细王道考研大题,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;
         

继续阅读