导航:首页 > 源码编译 > 数据结构比对源码

数据结构比对源码

发布时间:2022-06-10 09:40:43

A. C语言编程,请写出采用的数据结构和具体源码

程序比较复杂,应该是大实验吧

B. 数据结构,求源代码,c/c++


已发送,请查收。[email protected]

C. 用到数据结构的程序源代码

#include "stdio.h"
#include "malloc.h"
struct Bitree {
char nodes;
struct Bitree *lchild;
struct Bitree *rchild;
};
struct node {
char this;
struct node *next;
};
build( )
{
struct Bitree *b,*bn; /*b指向二叉树,bn为操作数

*/
struct node *c,*cn; /*c放置节点,作为一个小的队列.操作cn*/
int i,j,k;
char no;
i=1; /*每层有i个节点*/
printf("now we'll build the binary tree,,in the process,if the node is not exist ,enter '#'.first enter a boot\n"); /*先输入根节点*/
c=(struct node *)malloc(sizeof(struct node));
b=(struct Bitree *)malloc(sizeof(struct Bitree));
scanf("%c",&no);
c->this=no;
b->nodes=no;
bn=b;
do
{
j=2*i; /*i的下一层有2i个节点,*/
for(k=1;k<=i;k++)
{
bn=c->this;
printf("the left child of %c:",c->this);
scanf("%c",&no);
bn->lchild=(struct Bitree *)malloc(sizeof(struct Bitree));
bn->lchild->nodes=no;
if (no=="#")
{
j=j-1; /*如果节点的孩子为空,节点数-1*/
}
else
{
cn->next=(struct Bitree *)malloc(sizeof(struct Bitree));
cn->next->this=no;
cn=cn->next;
};
printf("the right child of %c:",c->this);
scanf("%c",&no);
bn->rchild=(struct Bitree *)malloc(sizeof(struct Bitree));
bn->rchild->nodes=no;
if(no=="#")
{
j=j-1;
}
else
{
cn->next=(struct Bitree *)malloc(sizeof(struct Bitree));
cn->next->this=no;
cn=cn->next;
};
c=c->next;
};
i=j;
}while(i!=0);
}
firstorder(struct Bitree *n)
{
printf("%c",n->nodes);
if(n->nodes=="#")
;
else
firstorder(n->lchild);
firstorder(n->rchild);
}

main()
{
struct Bitree *o;
build(o);
firstorder(o);
}

D. 数据结构问题,希望有完整源代码

先看题目,顺序表L的数据元素是整数且非递增有序,也就是有序的。

//1,2,3,3,4,5,8,8,.:非递减排列
//9,8,7,7,6,5,5,2,1,.:非递增排列

我们只需要使用两个标记,一个i,一个len,

然后线性扫描一遍线性表L,判断相邻两个数是否相等,相等len就不变,不想等len就+1.并且更新数组的值。最后注意边界条件即可。


代码实现如下,如果喜欢cout可以自行修改。线性表直接使用的数组表示。

#include<iostream>
#include<cstdio>
usingnamespacestd;
constintMAXN=256;

intmain(){


intL[MAXN],n,i,j,len,t;
scanf("%d",&n);

//根据键盘输入数据建立顺序表L
for(i=0;i<n;++i){
scanf("%d",&L[i]);
}

//输出顺序表
for(i=0;i<n;++i){
printf("%d",L[i]);
}
printf(" ");

//以O(n)的时间复杂度完成对值相同多余元素的删除
for(i=1,len=0;i<n;++i){
if(L[i]!=L[i-1]){
L[len]=L[i-1];
++len;
if(i==n-1){//注意边界条件
L[len]=L[i];
++len;
}
}
if(i==n-1&&L[i]==L[i-1]){//注意边界条件
L[len]=L[i];
++len;
}
}

//输出删除值相同多余元素后的顺序L
for(i=0;i<len;++i){
printf("%d",L[i]);
}
printf(" ");

//逆置顺序表L
for(i=0,j=len-1;i<=j;++i,--j){
t=L[i];
L[i]=L[j];
L[j]=t;
}

//输出逆置后的顺序表L
for(i=0;i<len;++i){
printf("%d",L[i]);
}
printf(" ");

return0;
}

//justdoit


E. 数据结构(C语言版)10.3快速排序源代码

void quiksort(int a[],int low,int high)
{
int i = low;
int j = high;
int temp = a[i];

if( low < high)
{
while(i < j)
{
while((a[j] >= temp) && (i < j))
{
j--;
}
a[i] = a[j];
while((a[i] <= temp) && (i < j))
{
i++;
}
a[j]= a[i];
}
a[i] = temp;
quiksort(a,low,i-1);
quiksort(a,j+1,high);
}
else
{
return;
}
}

void main()
{
int arry[5] = {23,1,21,4,19};
quiksort(arry,0,4);
for(i=0;i<5;i++)
{
printf("%d ",arr[i]);
}
printf("\n");
}
这是源码另外博客里面还有详细解释你可以进去看看

F. 数据结构C语言。求源代码

这里L是函数输入链表的头结点,L->next指向链表的第一个元素。
进入Reverse函数,先将p、q这两个临时指针指向链表的第一个元素。此时将L->next赋为空值,即L的next不再指向链表第一个元素了(想想此函数的目的是:要将L->next从链表的一头指向另一头。就回明白这里的含义了)
进入循环,这时p、q都指向了链表的第一个元素,循环结束条件是q等于空,即while(q)表示如果q不为空NULL,则进行循环。

q=q->next; //既然q不等于空,q就再往后走走,看看还有没有结点。
p->next=L->next;
L->next=p;
p=q;
//这里L->next是上一次循环时指向的p,而后p走到下一个节点,那么这里p->next=L->next就是将p当前节点的next指到它前一个节点去。从而达到逆序的效果。

这里可能你会觉得最开始L->next=NULL,很奇怪~
其实不会,第一个节点的next将指向L->next即为空,因为第一个节点正是反向后的尾巴,最后一个节点,它的next应该为空才对。

循环进行第二轮时,你就应该明白,此时q会先跑到第三个节点去,当前的p指向第二个节点,L->next在第一轮循环中指向了第一个节点,然后将第二个节点的next指向了第一个节点。L->next又指向当前的p,即第二个节点,这次循环的最后p又追上q,指向了第三个节点,如此循环,直到q等于原链表的最后一个节点的next,这应该是空NULL,结束循环。

G. 为什么有些人的数据结构学的那么好,我感觉怎么理解伪代码与源代码比较难

数据结构学习的是一种计算机抽象思想,通过介绍一个个经典数据结构的原理,来锻炼提高自身的计算机抽象能力。当然,在这个过程中,一定要不断的实践,在实践过程中理解这些思想,并积累相应的经验。针对,理解代码的困难,建议首先巩固编程语言基础,然后在理解代码之前一定要先理解结构的基本思想,至少要先在逻辑上理解这些结构和其相应的基本操作,这之后再去编写代码(或参考),这样才能取得不错的效果。希望能够对你有所帮助!~

H. 求数据结构(c语言版)程序源代码

1 #include <string.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4
5 #define MAX_POS_NUM 100
6 #define MAX_STR_LEN 1024
7
8
9 //1. get all position of str_z in str_x
10 int get_sub_str_pos(const char * str_x, const char * str_z, int sub_str_pos[])
11 {
12 if (NULL == str_x || NULL == str_z)
13 {
14 printf("in error!\n");
15 return -1;
16 }
17
18 const char * pos_ptr = NULL;
19
20 pos_ptr = strstr(str_x,str_z);
21
22 int i=0;
23 while(pos_ptr)
24 {
25 printf("substring positon:%d\n",pos_ptr-str_x+1);
26 sub_str_pos[i] = pos_ptr - str_x + 1;
27 pos_ptr = strstr(pos_ptr+strlen(str_z),str_z);
28 i++;
29 }
30
31 return 0;
32 }
33
34 //2. get max length common string of str_x and str_y
35 char * get_max_com_str(const char * str_x, const char * str_y)
36 {

37 int x_len = strlen(str_x);
38 int y_len = strlen(str_y);
39
40 char * tmp_str = new char[y_len+1];
41
42 for(int i=y_len; i>0; i--) // i is substring length
43 {
44 if (i>x_len)
45 continue;
46 for(int j=0;j<=y_len-i; j++) // j is substring start postion
47 {
48 snprintf(tmp_str,i+1,"%s",str_y);
49 if (strstr(str_x,tmp_str))
50 {
51 printf("%s\n",tmp_str);
52 printf("max common substring length:%d\n",i);
53 return tmp_str;
54 }
55 }
56 }
57
58 return NULL;
59 }
60
61 //3. replace all substring in question 1
62 char * replace_sub_str(const char * str_x, char * max_com_str, int sub_str_pos[], int sub_str_len)
63 {
64 char * replaced_str = new char[MAX_STR_LEN];
65
66 int sub_pos = sub_str_pos[0];
67 int l=0; // l is sub_str_pos index
68 int i=0,j=0; //i is str_x pos, j is replaced_str pos
69
70 while(*str_x)

71 {
72 if (i==sub_pos-1) // replace from this position
73 {
74 // printf ("i:%d,\n",i);
75 for (int k=0; k<strlen(max_com_str); k++)
76 {
77 *(replaced_str + j) = * (max_com_str + k);
78 j++;
79 }
80 i += sub_str_len;
81 str_x += sub_str_len;
82 l++;
83 sub_pos = sub_str_pos[l];
84 continue;
85 }
86 *(replaced_str+j) = *str_x++;
87 i++;
88 j++;
89 }
90
91 * (replaced_str + j) = '\0';
92
93 return replaced_str;
94 }
95
96 int main()
97 {
98 const char * str_x = "abcabcabc";
99 const char * str_y = "cabcd";
100 const char * str_z = "abc";
101
102 int sub_str_pos [MAX_POS_NUM] = {0};
103
104 char * max_com_str = NULL;

105
106 char * replaced_str = NULL;
107
108 get_sub_str_pos(str_x,str_z,sub_str_pos);
109 max_com_str = get_max_com_str(str_x,str_y);
110
111 printf("max common str: %s\n",max_com_str);
112
113 replaced_str = replace_sub_str(str_x, max_com_str, sub_str_pos, strlen(str_z));
114 printf("repalced str: %s\n",replaced_str);
115
116 return 0;
117 }

I. 数据结构各种算法或源代码从哪找

可以去书店找一下,会有里面是数据机构整个程序实现的参考书的

阅读全文

与数据结构比对源码相关的资料

热点内容
積架小型空气压缩机 浏览:555
绿盾文档加密系统哪里有卖 浏览:637
我的世界怎么开挂在服务器里面 浏览:789
西门子自锁正反转编程图 浏览:749
出国英语pdf 浏览:920
算法线性匹配 浏览:674
山东省dns服务器云主机 浏览:554
安卓5g软件怎么隐藏 浏览:839
编译内核空间不足开不了机 浏览:887
汉纪pdf 浏览:474
在哪里下载国家医保app 浏览:657
没有与文件扩展关联的编译工具 浏览:426
我的世界反编译mcp下载 浏览:19
安卓手柄下载什么软件 浏览:70
pushrelabel算法 浏览:850
硬盘资料部分文件夹空白 浏览:617
cssloader的编译方式 浏览:941
java面板大小 浏览:506
怎么用命令方块打出字体 浏览:500
台湾加密货币研究小组 浏览:299