- 博客(21)
- 收藏
- 关注
原创 1111 Online Map (30 分)
//二刷自解 }@TOC 欢迎使用Markdown编辑器 你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Markdown编辑器, 可以仔细阅读这篇文章,了解一下Markdown的基本语法知识。 新的改变 我们对Markdown编辑器进行了一些功能拓展与语法支持,除了标准的Markdown编辑器功能,我们增加了如下几点新功能,帮助你用它写博客: 全新的界面设计 ,将会带来全新的写作体验; 在创作中心设置你喜爱的代码高亮样式,Markdown 将代码片显示选择的高亮样式
2021-11-09 09:29:43
150
原创 剑指 Offer 09. 用两个栈实现队列
第一遍没看懂输入输出,后面看懂了,又搞不清函数的意思,自己写了一堆乱七八糟的,最后还是看了题解C语言 typedef struct { int Stack1[10001]; int Stack2[10001]; int Top1; int Top2; } CQueue; CQueue* cQueueCreate() { CQueue* Q=(CQueue*)malloc(sizeof(CQueue)); Q->Top1=Q->Top2=-1;
2021-05-03 17:43:32
106
原创 剑指 Offer 18. 删除链表的节点
/** Definition for singly-linked list. struct ListNode { int val; struct ListNode *next; }; */ struct ListNode* deleteNode(struct ListNode* head, int val){ if(headNULL)return NULL; struct ListNode* H=head; if(head->valval) { struct ListNode* H1=
2021-05-02 15:54:51
126
原创 剑指 Offer 22. 链表中倒数第k个节点(双指针)
首刷看题解 自己写还错了 ERROR: /** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ struct ListNode* getKthFromEnd(struct ListNode* head, int k){ struct ListNode* slow=head; struct ListNode*
2021-05-02 15:16:03
82
原创 206. Reverse Linked List(迭代+递归)
首刷自解(类似于在链表的头上插入节点) 迭代 /** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ struct ListNode* reverseList(struct ListNode* head){ struct ListNode* H=(struct ListNode*)malloc(sizeof(stru
2021-04-26 10:37:58
229
原创 203. Remove Linked List Elements(迭代+递归)
/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ struct ListNode* removeElements(struct ListNode* head, int val){ if(head==NULL)return head; struct ListNode* H=(struct ListNode
2021-04-25 12:10:10
137
原创 160. Intersection of Two Linked Lists(暴力+双指针)
首刷自解 /** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ struct ListNode *getIntersectionNode(struct ListNode *headA, struct ListNode *headB) { struct ListNode *HA=headA; struct Li
2021-04-24 13:32:50
92
原创 141. Linked List Cycle | | 剑指 Offer 22. 链表中倒数第k个节点 | | 876. 链表的中间结点
/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ bool hasCycle(struct ListNode *head) { if(head==NULL||head->next==NULL) return false; struct ListNode *slow=head; stru
2021-04-23 17:18:01
120
原创 83. Remove Duplicates from Sorted List(迭代+递归)
/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ struct ListNode* deleteDuplicates(struct ListNode* head){ struct ListNode* H=head; while(head!=NULL) { //if(head-&g
2021-04-22 18:10:33
175
原创 21. Merge Two Sorted Lists(迭代+递归)
/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ struct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2){ if(!l1)return l2; if(!l2)return l1; struct ListNode* H=(struc
2021-04-21 10:41:21
131
原创 28. Implement strStr() (strstr库的实现以及KMP算法)
库函数strstr的实现 int strStr(char * haystack, char * needle){ int L1=strlen(haystack); int L2=strlen(needle); int i,j; for(i=0;i+L2<=L1;i++) { int temp=i; for(j=0;j<L2;j++) { if(haystack[temp++]==nee
2021-04-20 20:16:30
78
原创 浙江大学数据结构(C语言实现)7-3 Pop Sequence (25 分)(数组模拟堆栈)
#include<stdio.h> #include<stdlib.h> #define MAXN 1005 typedef struct stack *Stack; struct stack { int Data[MAXN]; int Top; }; int main() { int N,M,K; scanf("%d %d %d",&M,&N,&K); int A[MAXN]; while(K--) { int x=1,temp=1;
2021-03-27 15:00:41
585
原创 (浙江大学数据结构C语言)02-线性结构1 两个有序链表序列的合并 (15 分)
List Merge(List L1,List L2) { List L=(List)malloc(sizeof(struct Node)); //int *Head=L;应该用List Head List Head=L; List L1F=L1->Next; List L2F=L2->Next; //while(L1&&L2)错误L1,L2均为头结点为空不进入while while(L1F&&L2F) { if(L1F->Data
2021-03-12 14:47:06
579
原创 (浙江大学数据结构C语言实现)6-10 二分查找 (20 分)
Position BinarySearch(List L,ElementType X) { int Left=1; int Right=L->Last; int Center=(Left+Right)/2; while(X!=L->Data[Center]&&Left<=Right)//傻子把!=写成了=! { if(X>L->Data[Center]) { Left=Center+1; } else Right=Center
2021-03-12 13:36:32
338
原创 (浙江大学数据结构C语言详解不懂可问)7-1 Maximum Subsequence Sum (25 分)
#include<stdio.h> #include<stdlib.h> void MaxSubseqSum(int A[],int N); int main() { int N; scanf("%d",&N); int *A=(int *)malloc(sizeof(int)); int i; for(i=0;i<N;i++) { scanf("%d",&A[i]); } MaxSubseqSum(A,N); free(A); retu
2021-03-12 13:02:12
265
原创 (浙江大学数据结构C语言实现)7-6 列出连通集 (25 分)
#include<stdio.h> #include<stdlib.h> #define MAXN 10 typedef struct GNode *PtrToG; struct GNode { int Nv; int Ne; int a[MAXN][MAXN]; }; int Visited[MAXN]={0}; PtrToG CreateGraph(int N,int E); void DFS(PtrToG G,int Data); void DFSShow(PtrToG
2021-03-10 19:06:01
257
原创 (浙江大学数据结构C语言实现)7-8 File Transfer (25 分)
#include<stdio.h> #include<stdlib.h> typedef int ElementType; typedef int SetName; typedef ElementType SetType[10001]; SetName Find(SetType S,ElementType X); void Union(SetType S,SetName Root1,SetName Root2); void Input_connection(SetType S); v
2021-03-09 11:47:13
391
原创 (浙江大学数据结构C语言实现)7-5 堆中的路径 (25 分)
#include<stdio.h> #include<stdlib.h> int H[1001]; int size; void Create(); void Insert(int X); int main() { int N,M,i,j,X,Index; scanf("%d %d",&N,&M); Create(); for(i=0;i<N;i++) { scanf("%d",&X); Insert(X); } for(i=0;i
2021-03-08 13:37:42
252
转载 (浙江大学数据结构C语言实现)7-2 Reversing Linked List (25 分)
#include<stdio.h> #include<stdlib.h> #define MAXN 100010 typedef struct List Node; //*Node 发生段错误 ? struct List { int Data; int Next; }; Node A[MAXN]; int list[MAXN]; void Swap(int *a,int *b); void Reverse(int *list,int a,int b); int main() {
2021-03-08 10:59:28
567
2
原创 (浙江大学数据结构C语言实现)7-3 树的同构 (25 分)
#include<stdio.h> #include<stdlib.h> #define ElementType char #define Null -1 #define Tree int #define MaxTree 10 struct TreeNode { ElementType Data; Tree Left; Tree Right; }Tree1[MaxTree],Tree2[MaxTree]; Tree BuildTree(struct TreeNode T[])
2021-03-06 16:58:09
382
原创 (浙江大学数据结构C语言实现)01-复杂度1 最大子列和问题 (20 分)
#include<stdio.h> #include<stdlib.h> int MaxSubseqSum(int a[],int N); int i; int main() { int K; scanf("%d",&K); int *a=(int *)malloc(sizeof(int)*K); int i; for(i=0;i<K;i++) { scanf("%d",a+i); } int Max=MaxSubseqSum(a,K); printf("%d",Max
2021-03-06 12:40:42
174
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人