数据结构与算法分析

/头插法

LinkList *CreateListF(){

char ch;

LinkList *head=NULL;

while((ch=getchar())!='#'){

LinkList s=(LinkList )malloc(sizeof(LinkList));

s->data=ch;

s->next=head;

head=s;

}

return head;

}

//尾插法

LinkList *CreateListR(){

char ch;

LinkList *head=NULL,*s,r=NULL;
while((ch=gether())!='#'){
s=(LinkList
)malloc(sizeof(LinkList));

s-data=ch;

if(head==NULL){

head=s;

}else{

r->next=s;

}

r=s;

}

if(r!=NULL) r->next=NULL;

return head;

}

//头结点尾插法

LinkList *CreatList(){

char ch;

LinkList head=(LinkList )malloc(sizeof(LinkList));

LinkList *r=head,s;
while((ch=gether())!='#'){
s=(LinkList
)malloc(sizeof(LinkList));

s->data=ch;

r->next=s;

r=s;

}

r->next=NULL;

return head;

}

//顺序栈

#define MAXSIZE 1020

typedef int Datatype;

typedef struct{

Datatype dataMAXSIZE;

int Top;

}SequenStack;

//链栈

typedef int Datatype;

typedef struct node{

Datatype element;

struct node *next;

}LinkList;

LinkList *Top;

//fibonacci递归

int Fib(int n){

if(n0) return 0;
if(n1) return 1;

return Fib(n-1)+Fib(n-2);

}

//优化

int FibDP(int n){

if(n<=) return n;

int dpn-1;

dp0=0;

dp1=1;

for(int i=2;i<=n;i++){

dpi=dpi-1+dpi-2;

}

rerurn dpn

}

相关推荐
老师我太想进步了20263 小时前
【数据结构-15】实现链式结构二叉树
c语言·数据结构
liulilittle3 小时前
认识麻将 —— 流水及对账
算法·游戏·lua·对账·流水·资金·玩法
xiangxueCode5 小时前
数据结构:容器适配器之优先级队列
数据结构·优先级队列
鱼很腾apoc6 小时前
【Redis】第2期 详解Redis五大数据结构:命令+C++实现、渐进式遍历与数据库管理
linux·服务器·c语言·数据结构·c++·redis·学习
郝学胜-神的一滴6 小时前
Effective Python 条款44:善用属性注解
开发语言·c++·vscode·python·算法·stl
青少儿编程课堂1 天前
第十八届蓝桥杯青少组图形化真题:校园分形雪花绘制解析(全国青少年信息素养大赛·电子学会图形化考级冲刺)
c++·python·算法·bfs·信息学竞赛
geovindu1 天前
python: KNeighborsClassifier K
开发语言·后端·python·算法
让我们一起加油好吗1 天前
【数据结构】线段树详解
数据结构·c++·算法·线段树·洛谷
路灯中转站1 天前
数据结构C语言版(什么是数据类型)
数据结构