SDUT 链表专题
来源:互联网 发布:禅道部署到linux 编辑:程序博客网 时间:2024/05/18 11:46
#include<bits/stdc++.h>using namespace std;typedef struct node{ int data; node *next;}node;///顺序建表//node *creat(int n)//{// node *head, *p;// head = new node;// head->next = NULL;// for(int i = 0; i < n; i++)// {// p = new node;// cin >> p->data;// p->next = head->next;// head->next = p;// }// return head;//}///逆序建表node *creat(int n){ node *head, *p; head = new node; head->next = NULL; for(int i = 0; i < n; i++) { p = new node; cin >> p->data; p->next = head->next; head->next = p; } return head;}///逆置//node *Rev(node *head)//{// node *p, *q;// p = head->next;// q = p->next;// head->next = NULL;// while(p)// {// p->next = head->next;// head->next = p;// p = q;// if(q)// q = q->next;// }// return head;//}///合并//node *Merge(node *head1, node *head2)//{// node *p, *q, *tail;// tail = head1;// p = head1->next;// q = head2->next;// free(head2);// while(p && q)// {// if(p->data < q->data)// {// tail->next = p;// tail = p;// p = p->next;// }// else// {// tail->next = q;// tail = q;// q = q->next;// }// }// if(q)// tail->next = q;// if(p)// tail->next = p;// return head1;//}///输出void show(node *head){ node *p; p = head->next; while(p) { if(p->next) printf("%d ", p->data); else printf("%d\n", p->data); p = p->next; }}///拆分//void di(node *head)//{// int n, m;// n = m = 0;// node *head1, *head2, *tail1, *tail2, *p;// head1 = new node;// head2 = new node;// head1->next = NULL;// head2->next = NULL;// tail1 = head1;// tail2 = head2;// p = head->next;// while(p)// {// if(p->data % 2 == 0)// {// n++;// tail1->next = p;// tail1 = p;// p = p->next;// }// else// {// m++;// tail2->next = p;// tail2 = p;// p = p->next;// }// }// tail1->next = NULL;// tail2->next = NULL;// printf("%d %d\n", n, m);// show(head1);// show(head2);//}///有序链表建立//node *creat(int n)//{// int x;// node *head, *p, *q, *nod;// head = new node;// head->next = NULL;// for(int i = 0; i < n; i++)// {// cin >> x;// p = head;// q = p->next;// while(q && q->data < x)// {// p = p->next;// q = q->next;// }// nod = new node;// nod->data = x;// p->next = nod;// nod->next = q;// }// return head;//}///删重int Del(node *head){ node *p, *q, *r; int n = 0; p = head->next; while(p) { if(p->next)///老毛病了,搞什么鬼!! q = p; r = q->next; while(r) { if(r->data == p->data) { q->next = r->next; r = r->next; n++; } else { q = q->next; r = r->next; } } p = p->next; } return n;}int main(){ ios::sync_with_stdio(false); node *head; int n; cin >> n; head = creat(n); printf("%d\n", n); show(head); printf("%d\n", n - Del(head)); show(head); return 0;}
阅读全文
0 0
- SDUT 链表专题
- SDUT专题整理——顺序表
- SDUT 栈和队列专题
- sdut 素数链表
- sdut 双向链表
- SDUT OJ 双向链表
- SDUT 2054 双向链表
- sdut acm 双向链表
- 专题:单向链表
- 链表专题总结
- 链表专题
- 双向链表(SDUT 2054)
- sdut 2116 顺序建立链表
- sdut oj2178 链表的有序集合
- SDUT-oj 链表的有序集合
- 面试题目 链表专题
- 面试题目 链表专题
- lintcode 链表专题总结
- 输入某年某月某日,判断这一天是这一年的第几天?
- 【软件测试的艺术(第三版)】读书笔记一
- order by子句
- 洛谷 2420 让我们异或吧
- Java:如何找出单链表中的倒数第k个元素
- SDUT 链表专题
- java 继承详解
- 数制转换C++ & 数据库索引
- 古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一 对兔子,假如兔子都不死,问每个月的兔子总数为多少?
- mysql基础知识
- Java基础:二进制转换
- kettle在win环境下安装部署
- LeetCode算法题——Generate Parentheses
- OpenCV教程 之 基础操作:图像的读入、输出、访问、Mat类、色彩缩减与线性融合