标签:pac null created ext file bsp head time name
/*************************************************************** Author :h-j-w Created Time :2017-11-26 File Name :头插法、尾插法 **************************************************************/ #include<bits/stdc++.h> #define OK 1 #define ERROR 0 using namespace std; typedef int status; typedef struct lnode { int data; struct lnode *next; }*Node, *linklist; //尾插法(顺序) void Tailcreate(linklist &l, int n) { Node p = (Node)malloc(sizeof(lnode)); p = l; for(int i = 0; i < n ; i++) { Node q = (Node)malloc(sizeof(lnode)); q->data =i; p->next = q; p = q; } p->next = NULL; } //头插法(逆序) void Headcreate(linklist &l, int n) { Node p; p = l; p->next = NULL; for(int i = 0; i < n ; i++) { Node q = (Node)malloc(sizeof(lnode)); q->data = i; q->next = p->next; p->next = q; } } void Print(linklist l) { Node p; p = l->next; while(p) { printf("%d",p->data); if(p->next != NULL) printf("--"); p = p->next; } printf("\n"); } int main() { linklist L; L = (linklist)malloc(sizeof(lnode)); Tailcreate(L,5); printf("尾插法\n"); Print(L); Headcreate(L,5); printf("头插法\n"); Print(L); }
标签:pac null created ext file bsp head time name
原文地址:http://www.cnblogs.com/hhkobeww/p/7898537.html