链表指针相关
链表 相关 指针
2023-09-14 09:11:42 时间
二叉树
typedef struct Node { int data; struct Node *lchild, *rchild; } Node, *Tree; int f, a[10005]; Tree build(int cur) { Tree T; if (f) { T = NULL; return T; } int p = a[cur]; if (p == -1) f = 1, T = NULL; else if (p == 0) T = NULL; else { T = (Node *)malloc(sizeof(Node)); T->data = p; T->lchild = build(cur * 2 + 1); T->rchild = build(cur * 2 + 2); } return T; } void destory(Tree t) { Tree cur = t; if (cur != NULL) { destory(cur->lchild); destory(cur->rchild); free(cur); cur=NULL; } }
链表
#include <stdio.h> #include <stdlib.h> struct node { int data; struct node *next; }; struct node *inset(struct node *head, int n) { int i; struct node *p, *q, *tail; q = head; for (i = 0; i < n; i++) { p = (struct node *)malloc(sizeof(struct node)); scanf("%d", &p->data); p->next = q->next; q->next = p; q = p; } return (head); } int main() { int i, j, n, m, a, b, c, k; struct node *head, *p, *q, *tail; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d%d%d", &m, &a, &b); head = (struct node *)malloc(sizeof(struct node)); head->next = NULL; head = inset(head, m); q = head; while (q->next != NULL) { k = 1; if ((q->next->data >= a) && (q->next->data <= b)) { k = 0; p = q->next; q->next = p->next; free(p); } if (k != 0) q = q->next; } p = head; p = p->next; int f = 0; if (p == NULL) { free(head); printf("-1"); } else while (p != NULL) { q = p; if (f) printf(" "); printf("%d", p->data); f = 1; p = p->next; free(q); } printf("\n"); } return 0; }
链表逆序
void reverse_linklist(struct node*& head) { node *p = head; if(p->next == NULL){ return; } head = p->next; reverse_linklist(head); p->next->next = p; p->next = NULL; }
TZOJ1216: 一元多项式求和
#include <bits/stdc++.h> using namespace std; struct Node { double coe; int exp; struct Node *next; }; Node *add(Node *a, Node *b) { Node *p = a; while (p->next) { if (p->next->exp > b->exp) { b->next = p->next; p->next = b; return a; } else if (p->next->exp == b->exp) { p->next->coe += b->coe; if (p->next->coe == 0) { Node *q = p->next; p->next = p->next->next; delete q; return a; } return a; } p = p->next; } b->next = p->next; p->next = b; return a; } void Print(Node *head) { Node *t = head; head = head->next; delete t; while (head) { if (fabs(head->coe) >= 1e-6) { printf("%.2f %d\n",head->coe,head->exp); } Node *p = head; head = head->next; delete p; } } int main() { int T; cin>>T; while (T--) { Node *head = new Node; head->next = NULL; int n; cin>>n; while (n--) { Node *t = new Node; cin>>t->coe>>t->exp; head = add(head, t); } cin>>n; while (n--) { Node *t = new Node; cin>>t->coe>>t->exp; head = add(head, t); } Print(head); if(T)cout<<"\n"; } return 0; }
CSS控制单词换行 word-break:break-all;
const double X::PI=acos(-1.0);
cout<<setiosflags(ios::fixed)<<setprecision(2)<<X::PI<<endl;
相关文章
- 浙江大学数据结构习题:02-线性结构1 两个有序链表序列的合并 (15分)
- Java实现 LeetCode 141 环形链表
- Java实现 LeetCode 138 复制带随机指针的链表
- python code practice(三):链表、栈、队列
- LeetCode(109):有序链表转换二叉搜索树
- 利用二级指针删除单向链表——笔记
- (链表专题) 83. 删除排序链表中的重复元素 ——【Leetcode每日一题】
- Algorithm:C++语言实现之链表相关算法(单链公共结点问题、一般LCA、括号匹配、最长括号匹配、逆波兰表达式Reverse Polish Notation、直方图矩形面积、收集雨水问题)
- python判断链表是否有环
- 面试题 02.07.返回 链表相交节点
- 剑指 Offer II 026. 重排链表
- 23. 合并K个升序链表-c语言
- 合并两个有序链表-c语言
- 反转链表-c语言描述
- 2.5 Floyd链表查环算法
- 习题 9.9 综合本章例9.9、例9.10和本章习题第7题、第8题,再编写一个主函数,先后调用这些函数。用以上5个函数组成一个程序,实现链表的建立、输出、删除和插入,在主函数中指定需要删除和插入结点。
- 【Linux 内核 内存管理】RCU 机制 ① ( RCU 机制简介 | RCU 机制的优势与弊端 | RCU 机制的链表应用场景 )
- 链表相关
- 编程算法 - 有序双循环链表的插入 代码(C)
- 剑指 Offer 06. 从尾到头打印链表
- LeetCode 141. 环形链表
- 【数据结构与算法】什么是双向循环链表?以及实现过程
- RT-Thread系列三 邂逅线程链表
- 内核链表分析