博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
链表函数(建立,删除重复元素,排序,输出)—— 链表的有序集合
阅读量:4973 次
发布时间:2019-06-12

本文共 2337 字,大约阅读时间需要 7 分钟。

/**************************************      Problem id    : SDUT OJ 2178       User name    : Silence-Debug       Result        : Accepted       Take Memory    : 316K       Take Time    : 0MS       Submit Time    : 2013-05-31 21:05:15    **************************************/ # include 
# include
struct node { int date; struct node *next; } ; struct node *creat(int n) { struct node *head, *tail, *p; head = (struct node *)malloc(sizeof(struct node)); head -> next = NULL; tail = head; for(int i = 0; i < n; i++) { p = (struct node *)malloc(sizeof(struct node)); scanf("%d", &p -> date); p -> next = NULL; tail -> next = p; tail = p; } return head; } void Delete(struct node *&head, int n) { struct node *p, *q, *t, *tail; p = head -> next; while(p) { q = p->next; t = p; while(q) { tail = q; if (p -> date == q -> date) { n--; t -> next = q -> next; q = q -> next; free(tail); } else { q = q->next; t = t->next; } } p = p -> next; } } void sortline(struct node *&head, int n) { struct node *p, *q; while(n--) { p = head -> next; q = p -> next; while(p -> next) { if(p -> date > q -> date) { int t = p -> date; p -> date = q -> date; q -> date = t; } p = p -> next; q = q -> next; } } } void output(struct node *head) { struct node *r = head; while(r -> next -> next != NULL) { printf("%d ", r -> next -> date); r = r -> next; } printf("%d\n", r -> next -> date); } int main(void) { int n; while(~scanf("%d", &n)) { struct node *head; head = creat(n); Delete(head, n); sortline(head, n); output(head); } return 0; }
View Code

 

 

转载于:https://www.cnblogs.com/Silence-AC/archive/2013/05/31/3111179.html

你可能感兴趣的文章
类对象
查看>>
[Voice communications] 声音的滤波
查看>>
SQL语言之概述(一)
查看>>
软件建模——第9章 毕业论文管理系统—面向对象方法
查看>>
[SDOI2008]洞穴勘测
查看>>
Difference between Linearizability and Serializability
查看>>
IDEA使用操作文档
查看>>
UIView
查看>>
添加日期选择控件
查看>>
bzoj4765: 普通计算姬 (分块 && BIT)
查看>>
看完漫画秒懂区块链
查看>>
Oracle命令类别
查看>>
stc12c5a60s2驱动TEA5767收音机模块硬件调试总结
查看>>
vue中提示$index is not defined
查看>>
css选择器
查看>>
看懂下面C++代码才说你理解了C++多态虚函数!
查看>>
ASP.NET上传下载文件
查看>>
Galaxy Nexus 全屏显示-隐藏Navigation Bar
查看>>
Spring中使用Velocity模板
查看>>
上周热点回顾(8.18-8.24)
查看>>