C与数据结构
虫钻米
这个作者很懒,什么都没留下…
展开
-
前缀求值+后缀转前缀
前缀求值+后缀转前缀#include<stdio.h>#include<stdlib.h>#include<math.h>#include<string.h>char *chartostr(char c){char *s;s=(char *)malloc(sizeof(char)*2);if(s==NULL)return NULL;s[0]=c;s[1]=’\0’;return s;}char *change(char *c){原创 2020-11-09 16:19:48 · 59 阅读 · 0 评论 -
二叉树建立、打印、求高度
#include<stdio.h>#include<stdlib.h>typedef struct BTree{ char data; struct BTree *child; struct BTree *brother;}BTree;typedef struct{ BTree *p; int level;}st;void print(BTree *p){ if(p!=NULL) { printf("%c\n",p->data);原创 2020-11-09 16:22:53 · 132 阅读 · 0 评论 -
二级指针(链表建立、打印)
#include<stdio.h>#include<stdlib.h>typedef struct LNode{ int data; struct LNode *next;}LNode;void insert(LNode *A,int i){ LNode *p; p=(LNode*)malloc(sizeof(LNode)); p->data=i; p->next=A->next; A->next=p;}/*void Sql原创 2020-11-09 16:24:30 · 154 阅读 · 0 评论 -
地图着色
求解可以有多少种不同的解法(回溯法、递归)#include<stdio.h>#include<stdlib.h>#include<math.h>#include<string.h>int count=0;typedef struct ArcNode//边表结点{ int adjvex;//邻接点域,存储该顶点对应的下标 struct ArcNode *nextarc; //链域,指向下一个邻接点} ArcNode;typed原创 2020-11-09 16:25:41 · 261 阅读 · 0 评论 -
单词计数问题
#include<stdio.h>#include<stdlib.h>#include<math.h>#include<string.h>typedef struct{ char a[20]; int count;}words;int check(char c){ if((c>='a'&&c<='z')||(c>='A'&&c<='Z')) return 1; else原创 2020-11-09 16:27:51 · 87 阅读 · 0 评论 -
N皇后问题
#include<stdio.h>#include<stdlib.h>#include<math.h>#include<string.h>typedef struct{ int x,y;}Location;int t=0;int check(int i,Location c[]){ int j; for(j=0;j<c[i].x;j++) { if( (c[i].x==c[j].x) ||c[i].y==c[j].y |原创 2020-11-09 16:28:22 · 53 阅读 · 0 评论 -
文件合并——几个注意点
有两个磁盘文件,各存放一行字母,要求把这两个文件中的信息合并,按照字母顺序排列,输出到文件C#include<stdio.h>#include<stdlib.h>int main(){ FILE *fp1,*fp2,*fp3; char s[100],temp,ch; int i,j; if((fp1=fopen("D:\\A.txt","r"))==NULL) //双引号 { printf("error!\n"); exit(0); } if((f原创 2020-11-19 20:45:46 · 160 阅读 · 0 评论 -
2008—7 单词词频
计算一行字符中单词的词频其中计算词频用二叉树计算2008年最后一题(有几个注意点)#include<stdio.h>#include<stdlib.h>#include<string.h>typedef struct BTnode{ //char *ch; char ch[20]; int count; struct BTnode *lchild,*rchild;}BTnode;void insert(BTnode **p,char *s)原创 2020-11-20 22:22:23 · 51 阅读 · 0 评论 -
2014—5 分解质因数
分解质因数(递归与非递归的方法)#include<stdio.h>#include<stdlib.h>int data[20],j=0;int prim(int n){ int i; for(i=2;i*i<=n;i++) { if(n%i==0) return 0; } return 1;}void f(int n,int i){ if(i>n) //注意条件 return; else { if(prim(i)原创 2020-11-27 22:34:02 · 304 阅读 · 0 评论 -
模拟——哈希表(除留余数法+链地址法)
#include<stdio.h>#include<stdlib.h>#include<string.h>#define maxsize 13typedef struct LNode{ int data; struct LNode *next;}LNode;typedef struct{ int length; LNode *list[20];}HashTable;int Hash(int key){ return key%maxsi原创 2020-11-29 22:55:36 · 634 阅读 · 1 评论 -
2017—6 求最长对称子串
#include<stdio.h>#include<stdlib.h>#include<string.h>int findmax(char *str){ int i,m,n,maxlen=1,s; for(i=1; i<strlen(str); i++) { s=1; //对称字符串长度为奇数的情况 m=i-1; n=i+1; while( m>=0 && n<strlen(原创 2020-12-03 00:08:13 · 108 阅读 · 0 评论 -
2020—4 线性复杂度求第K大的数
本题可以使用桶排序、基数排序、计数排序(我个人比较喜欢计数排序)下面的方法是基于快速排序(比较复杂,但是漏洞最少)#include<stdio.h>#include<stdlib.h>#include<string.h>int quicksort(int s[],int l,int r){ int i,j,x; if(l<r) { i=l; j=r; x=s[i]; while(i<j) { while(i<原创 2020-12-09 20:51:56 · 95 阅读 · 0 评论 -
模拟C——7
#include<stdio.h>#include<stdlib.h>#include<string.h>typedef struct{ int in; int info;}Vertextype;typedef struct{ float edges[50][50]; int n,e; Vertextype vex[50];}MGraph;MGraph create(){ int i,j; MGraph G; G.n=7; G.e原创 2020-12-10 21:10:15 · 96 阅读 · 0 评论 -
拓展——递归删除单链表中所有值为x的结点
#include<stdio.h>#include<stdlib.h>#include<string.h>typedef struct LNode{ int data; struct LNode *next;}LNode;LNode *create(int n){ LNode *L=(LNode*)malloc(sizeof(LNode)); LNode *s=NULL,*p=L; int i,j; for(i=0;i<n;i++) {原创 2020-12-11 18:31:37 · 419 阅读 · 0 评论 -
2020—6 岛屿周长和面积
递归求DEM的岛屿周长或者面积#include<stdio.h>#include<stdlib.h>#include<string.h>int getarea(int a[10][10],int i,int j){ if(i<0||i>=10||j<0||j>=10) return 0; else if(a[i][j]>0) { a[i][j]=0; return getarea(a,i-1,j)+getare原创 2020-12-14 21:50:44 · 95 阅读 · 0 评论