头插法、尾插法的理解
生活随笔
收集整理的这篇文章主要介绍了
头插法、尾插法的理解
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
/***************************************************************
Author :bryant~xw
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);
}
转载于:https://www.cnblogs.com/mcgrady_ww/p/7898537.html
总结
以上是生活随笔为你收集整理的头插法、尾插法的理解的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: Microsoft Windows Wo
- 下一篇: js、jquery实用小技巧集合