单链表头插法与尾插法的c语言实现(回顾)
生活随笔
收集整理的这篇文章主要介绍了
单链表头插法与尾插法的c语言实现(回顾)
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
typedef struct node{int data;node *next;
};
int main()
{node *head = NULL;node *tail = NULL;node *p = NULL;p = (node *)malloc(sizeof(node));if(p==NULL){printf("%s","没有足够的空间");}head = p;tail = p;for(int i=0;i<10;i++){node *pnew = (node*)malloc(sizeof(node));pnew ->data = i;//头插法:逆序if(i==0){pnew ->next = NULL;head ->next = pnew;}else{pnew ->next = head->next;head ->next = pnew;}//尾插法//pnew ->next = NULL;//p -> next = pnew;//p = p->next;}head = head->next;while(head!=NULL){printf("%d ",head->data);head = head->next;}return 0;
}
总结
以上是生活随笔为你收集整理的单链表头插法与尾插法的c语言实现(回顾)的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 【转载】Jsoup设置代理ip访问
- 下一篇: 学习向量量化