数据结构c语言入门代码Word文档格式.docx

上传人:b****7 文档编号:22388896 上传时间:2023-02-03 格式:DOCX 页数:21 大小:17.38KB
下载 相关 举报
数据结构c语言入门代码Word文档格式.docx_第1页
第1页 / 共21页
数据结构c语言入门代码Word文档格式.docx_第2页
第2页 / 共21页
数据结构c语言入门代码Word文档格式.docx_第3页
第3页 / 共21页
数据结构c语言入门代码Word文档格式.docx_第4页
第4页 / 共21页
数据结构c语言入门代码Word文档格式.docx_第5页
第5页 / 共21页
点击查看更多>>
下载资源
资源描述

数据结构c语言入门代码Word文档格式.docx

《数据结构c语言入门代码Word文档格式.docx》由会员分享,可在线阅读,更多相关《数据结构c语言入门代码Word文档格式.docx(21页珍藏版)》请在冰豆网上搜索。

数据结构c语言入门代码Word文档格式.docx

intgetelem(listl,inti,elem&

e)

e=*(l.head+i-1);

intlctelem(listl,eleme)

inti=0;

for(i;

i<

l.lenth;

i++)

if(*(l.head+i)==e)return1;

return0;

intinsert(list&

l,inti,eleme)

intj;

l.lenth++;

if(l.lenth>

l.size)

l.head=(elem*)realloc(l.head,(l.size+incrment)*sizeof(elem));

if(i>

l.lenth||i<

0)return0;

for(j=l.lenth;

j>

i;

j--)

*(l.head+j-1)=*(l.head+j-2);

*(l.head+i-1)=e;

intdlt(list&

l,inti)

l.lenth)return-1;

l.lenth--;

l.lenth+1||i<

for(j=i;

j<

l.lenth+1;

j++)

*(l.head+j-1)=*(l.head+j);

//以上就是数据结构的定义和操作部分voidfun1()

listl;

inti;

chare;

init(l,20);

insert(l,1,'

a'

);

insert(l,2,'

b'

insert(l,3,'

d'

for(i=1;

=3;

getelem(l,i,e);

printf("

%c\n"

e);

\n"

c'

=4;

e'

=5;

if(empty(l))printf("

nowthelistisempty\n"

dlt(l,1);

=2;

if(lctelem(l,'

))printf("

bisinthelist\n"

destroy(l);

voidpr_min(listl)

elemmin;

min=*l.head;

if(*(l.head+i)<

min)

min=*(l.head+i);

min=%d\n"

min);

voidmain()

l.lenth=n;

for(i=0;

*(l.head+i)=i+1;

pr_min(l);

数据结构2:

线性链表

typedefstructnode{

elemdata;

structnode*next;

}node,*linklist;

intcreat(linklist&

l=(linklist)malloc(sizeof(node));

l->

next=NULL;

l)return0;

intlenth(linklistl)

intj=1;

linklistgetl=l;

while(getl->

next)

getl=getl->

next;

j++;

returnj;

intput(linklistl,inti,eleme)

for(j=1;

//findtheinodeif(!

getl)return0;

getl->

data=e;

intaddone(linklistl,linklistb)

linklistcur_node=l;

//findthelastnode

while(cur_node->

cur_node=cur_node->

cur_node->

next=b;

b->

intinsert(linklistl,inti,linklistb)

linklistq;

i-1;

//findthei-1node

q=getl->

next=q;

intdlt(linklistl,inti)

//findtheinode

next=q->

free(q);

intvisit(linklistl)

while(cur_node)

cur_node->

data);

voiddao_visit(linklistl)

linklistrcv=l;

linklistrcv2=rcv;

elem*a;

intlenth=0;

while(rcv)

lenth++;

rcv=rcv->

a=(elem*)malloc(lenth*sizeof(elem));

while(rcv2)

a[i]=rcv2->

data;

rcv2=rcv2->

i++;

lenth;

a[lenth-1-i]);

//以上是数据结构定义,以及对它的操作voidmain()

linklistft;

//a

linklista;

//b

linklistb;

//c

linklistc;

//i

//char*a;

//charb[10]="

hello"

;

//a=b;

//printf("

%s"

a);

creat(ft);

creat(a);

creat(b);

creat(c);

put(ft,1,'

addone(ft,a);

put(ft,2,'

addone(ft,b);

put(ft,3,'

insert(ft,3,c);

i'

dlt(ft,2);

visit(ft);

dao_visit(ft);

%d\n"

lenth(ft));

//visit(b);

lenth(b));

}

数据结构3:

#include"

stdlib.h"

stdio.h"

typedefintelmtp;

typedefstruct{

elmtp*base;

elmtp*top;

intstksize;

}stack;

intinit(stack&

s,intsize)

s.base=(elmtp*)malloc(size*sizeof(char));

s.base)return0;

s.top=s.base;

s.stksize=size;

intpush(stack&

s,elmtpe)

*s.top=e;

s.top++;

intgettop(stacks,elmtp&

if(s.base==s.top)return0;

e=*(s.top-1);

intpop(stack&

s,elmtp&

s.top--;

//以上是。

//下面这个main函数是将10进制数转为8进制voidmain()

intn;

stacks;

init(s,10);

scanf("

%d"

&

n);

while(n)

push(s,n%8);

n=n/8;

while(pop(s,n))

%d\t"

n);

数据结构4:

#defineprprintf

inta=48;

structnode

structnode*parent;

structnode*lchild;

structnode*rchild;

};

typedefstructnode*root;

intcreat(root&

r)//创建结点

r=(root)malloc(sizeof(node));

r)return0;

r->

parent=0;

lchild=0;

rchild=0;

data=a++;

//添加关系

voidaddparent_lchild(rootparent,rootb){

parent=parent;

//成员赋值

parent->

lchild=b;

voidaddparent_rchild(rootparent,rootb){

rchild=b;

//先序遍历

voidpre_traverse(rootr)

r->

if(r->

lchild)

pre_traverse(r->

lchild);

rchild)

rchild);

//if(!

(r->

lchild||r->

rchild))

rootr[10];

creat(r[0]);

//pr("

r[0]->

r[0]);

//536

r[0]->

parent);

//536

//540

//544

//548random7;

&

data=r+12;

creat(r[1]);

creat(r[2]);

creat(r[3]);

creat(r[4]);

creat(r[5]);

addparent_lchild(r[0],r[1]);

addparent_rchild(r[0],r[2]);

addparent_lchild(r[1],r[3]);

addparent_rchild(r[1],r[4]);

addparent_lchild(r[2],r[5]);

6;

pr("

r[i]->

pre_traverse(r[0]);

附:

一道程序题

12345

23456

34567

45678

从1开始到8结束,可以横向和纵向移动,每次一格,问,共有多少总路径代码:

//#include<

#defineincrement10

intx;

inty;

}posion;

intid;

intde;

//posioncur;

}array;

posioncur_p;

arraycur_a;

}elem;

elem*base;

elem*top;

//staticintx=0,y=0;

s.base=(elem*)malloc(size*sizeof(elem));

s.base)exit(0);

elemgettop(stacks)

//if(s.top==s.base)return;

return*(s.top-1);

intempty(stacks)

if(s.top==s.base)return0;

s,eleme)

if(s.top-s.base>

=s.stksize)

s.base=(elem*)realloc(s.base,(s.stksize+increment)*sizeof(elem));

s)

//e=*(s.top-1);

arraya[5][6];

inti=0,j=0;

intcount=0;

elemcur_e;

//initposition

posionnow={0,0};

//inita[5][6]

4;

for(j=0;

5;

a[i][j].id=i+j+1;

a[i][j].de=0;

a[i][5].id=0;

a[i][5].de=0;

a[4][j].id=0;

a[4][j].de=0;

//initstack

init(s,30);

//for(i=0;

//{

//for(j=0;

%d"

a[i][j].de);

//}

//i=j=0;

/*

cur_e.cur_p=now;

cur_e.cur_a=a[now.x][now.y];

push(s,cur_e);

while(empty(s))

switch(gettop(s).cur_a.id)

case8:

count++;

pop(s);

if(a[gettop(s).cur_p.x][gettop(s).cur_p.y].de==1)now.y--;

elsenow.x--;

break;

case0:

default:

if(a[now.x][now.y].de==0)

a[now.x][now.y].de++;

now.y++;

//gettop(s).de+=1;

//x++;

elseif(a[now.x][now.y].de==1)

now.x++;

else

a[now.x][now.y].de=0;

if(empty(s))

count);

喜欢的话,多下几次,给好评吧

 

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工作范文 > 行政公文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1