链表的建立
来源:互联网 发布:无线网卡怎么改mac地址 编辑:程序博客网 时间:2024/06/14 08:26
分别采用头插法,尾插法,升序建立链表
#include<stdio.h>#include<stdlib.h>typedef struct _Node{int data;struct _Node *next;}Node;typedef struct _list{Node *head;}List;void add(List *pList,int number){Node *p=(Node*)malloc(sizeof(Node));p->data=number;p->next=NULL;Node *last=pList->head;if(last){while(last->next){last=last->next;}last->next=p;}else pList->head=p;}void add2(List *pList,int number){Node *p=(Node*)malloc(sizeof(Node));p->data=number;p->next=pList->head;pList->head=p;}void add3(List *pList,int number){Node *p=(Node*)malloc(sizeof(Node));p->data=number;p->next=NULL;if(pList->head==NULL||p->data<pList->head->data){ p->next=pList->head; pList->head=p;}else{Node *q=pList->head;while(q->next&&p->data>q->next->data){q=q->next;}if(q->next==NULL){q->next=p;}else{p->next=q->next;q->next=p;}}}void showL(List *pList){Node *p;for(p=pList->head;p;p=p->next){printf("%d ",p->data);} }int main(){List L;L.head=NULL;int n,temp;scanf("%d",&n);for(int i=0;i<n;i++){scanf("%d",&temp);add3(&L,temp);}//int m;//scanf("%d",&m);//ldelete(&L,m);showL(&L);}
阅读全文
0 0
- 链表的建立
- 链表的建立
- 链表的建立
- 链表的建立
- 链表的建立
- 链表的建立
- 链表的建立
- 二叉链表的建立
- 双向链表的建立
- 数据结构 链表的建立
- 双向链表的建立
- 双向链表的建立
- 简单链表的建立
- 双向链表的建立
- 邻接链表的建立
- 双向链表的建立
- 单向链表的建立
- 十字链表的建立
- 让你完全理解base64是怎么回事
- Android的IPC机制(一)——AIDL的使用
- java代理模式
- tensorflow学习---Variable
- 在 2018 年来临之际,你应该知道的 Vue.js 的 11 个组件库
- 链表的建立
- 企业激励机制模型 (Business Motivation Model)
- 无法定位程序输入点ucrtbase.terminate有感
- tensorflow API:tf.not_equal
- Dubbo入门---搭建一个最简单的Demo框架
- IAR参数变量(从IAR的帮助文件里翻译的)
- 路由
- 设计模式知识连载(21)---代理模式:
- umeditor无法显示包含html、body标签解决办法