数据结构c语言版源代码(数据结构 c语言中文网)
admin 发布:2022-12-19 20:53 174
今天给各位分享数据结构c语言版源代码的知识,其中也会对数据结构 c语言中文网进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、C语言数据结构线性表源代码问题
- 2、数据结构 冒泡排序 c语言 源代码 急用啊
- 3、用C语言和数据结构编写一个简单的程序(求源代码)
- 4、急求通讯录管理系统(有链表的)数据结构c语言版的源代码。要求c++可以测试通过
- 5、求数据结构(c语言版)程序源代码
C语言数据结构线性表源代码问题
#include stdio.h#include stdlib.h#include time.h#define MAXSIZE 100#define TRUE 1#define ERROR 0typedef int ElemType;typedef struct list { ElemType *elme; int length;}Sqlist;int initlist(Sqlist *L) { L-elme = (ElemType *)malloc(MAXSIZE * sizeof ElemType); if(L-elme == NULL) return ERROR; L-length = 0; return TRUE;}int insertlist(Sqlist *L,int pos,ElemType e) { int i; if(L-length == 0) { // 第一元素无条件插入 L-elme[0] = e; L-length = 1; return TRUE; } if(L-length = MAXSIZE) { printf("表满。length = %d。\n",L-length); return ERROR; } if(pos 1 || pos L-length) { printf("插入位置不合理。\n"); printf("表长:%d,位置:%d\n",L-length,pos); printf("元素%d未能插入。\n",e); return ERROR; } for(i = L-length; i pos - 1; --i) L-elme[i] = L-elme[i - 1]; L-elme[pos - 1] = e; ++L-length; return TRUE;}int deletelist(Sqlist *L,int pos) { int i; if(pos 1 || pos L-length) { printf("删除位置不合理。\n"); printf("表长:%d,位置:%d\n",L-length,pos); printf("第%d个元素未能删除。\n",pos); return ERROR; } for(i = pos - 1; i L-length - 1; ++i) L-elme[i] = L-elme[i + 1]; --L-length; return TRUE;}void displaylist(Sqlist *L) { int i; for(i = 0;i L-length; i++) printf("%d ",L-elme[i]); printf("\n");}int main(void){ Sqlist *L = (Sqlist *)malloc(sizeof(Sqlist)); int i,n,pos,res; initlist(L); printf("Enter n:"); scanf("%d",n); srand((unsigned)time(NULL)); for(i = 0; i n; ++i) { res = insertlist(L,i,rand() % 100); if(res == ERROR) --i; } displaylist(L); printf("Enter pos:"); scanf("%d",pos); deletelist(L,pos); displaylist(L); return 0;}
数据结构 冒泡排序 c语言 源代码 急用啊
void bubble_sort(int *x, int n)
{
int j, k, h, t;
for (h=n-1,h=k; h0; h--) /*循环到没有比较范围*/
{
for (j=0, k=0; jh; j++) /*每次预置k=0,循环扫描后更新k*/
{
if (*(x+j) *(x+j+1)) /*大的放在后面,小的放到前面*/
{
t = *(x+j);
*(x+j) = *(x+j+1);
*(x+j+1) = t; /*完成交换*/
k = j; /*保存最后下沉的位置。这样k后面的都是排序排好了的。*/
}
}
}
}
用C语言和数据结构编写一个简单的程序(求源代码)
/*使用递归,理论上说可以对任意多位数组合,但位数太多了,可能发生堆栈溢出.
以下程序在VC++6.0中编译通过.
*/
#include stdio.h
#include string.h
#define MAX_NUMBER 6 //修改这个参数来允许最大的位数,现设为6位
void GetZhe (const char * preStr,const char * strNum)
{
char newPreStr[MAX_NUMBER];
char tmpStr[MAX_NUMBER];
int i,j,k,iCnt;
k = strlen(strNum);
if (kMAX_NUMBER) {
printf("超过最大允许的位数:%d!",MAX_NUMBER);
return ;
}
switch(k)
{
case 0:
return;
case 1:
strcpy(tmpStr,preStr);
strcat(tmpStr,strNum);
printf("%s\r\n",tmpStr);
break;
default:
tmpStr[0] = 0;
for (i=0;ik;i++)
{
strcpy(newPreStr,preStr);
j = strlen(newPreStr);
newPreStr[j] = strNum[i];
newPreStr[j+1] = 0;
iCnt = 0;
for (j=0;jk;j++)
{
if(j != i)
{
tmpStr[iCnt] = strNum[j];
iCnt ++ ;
}
}
tmpStr[iCnt] = 0;
GetZhe(newPreStr,tmpStr);
}
}
}
int main(int argc, char* argv[])
{
GetZhe("","123456");
return 0;
}
急求通讯录管理系统(有链表的)数据结构c语言版的源代码。要求c++可以测试通过
这个绝对满足了你的要求了,谢谢采纳`
#includeiostream.h
#includestring
#includestdlib.h
class List;
class person
{
public:
friend class List;
private:
person() {next=0;}
person *next;
char name[10],tel[15];
};
class List
{
public:
List(){list=0;}
int gncd(); // 功能菜单
int print(); // 输出所有信息
int append(); // 增加一个信息
int revise(); // 根据姓名、电话修改信息
int dele(); // 根据姓名、电话删除信息
int exit(); // 退出
private:
person *end();
person *list;
};
int List::exit()
{
abort();
return 1;
}
int List::gncd()
{
cout"************欢迎使用****************************"endl;
cout"1.输入信息。"endl;
cout"2.根据姓名、电话修改信息。"endl;
cout"3.根据姓名、电话删除信息"endl;
cout"4.输出所有现有成员信息"endl;
cout"5.退出"endl;
cout"选择:";
int a;
cina;
switch(a)
{
case(1):this-append();break;
case(2):this-revise();break;
case(3):this-dele();break;
case(4):this-print();break;
case(5):this-exit();break;
}
this-gncd();
return 1;
}
int List::print()
{
if(list==0)
{
cout"为空或没输入内容"endl;
return 0;
}
person *p=list;
while(p!=NULL)
{
cout"姓名:"p-nameendl;
cout"电话:"p-telendl;
p=p-next;
}
coutendl;
return 1;
}
int List::append()
{
person *p=new person;
cout"请输入姓名:"endl;
cinp-name;
cout"请输入电话号码:"endl;
cinp-tel;
char temp;
cout"是否继续输入(y/n)";
cintemp;
if(temp=='y'||temp=='Y')
this-append();
if(list==0)
list=p;
else
(end())-next=p;
return 1;
}
person *List::end()
{
person *p,*q;
for(q=p=list;p;q=p,p=p-next) ;
return q;
}
int List::revise()
{
person *p=list;
char temp[20];
cout"你选择了根据姓名、电话修改信息。"endl"请输入将要修改的姓名或电话:";
cintemp;
int i=0;
while(p!=NULL)
{
if(!strcmp(p-name,temp)||!strcmp(p-tel,temp))
{
i=1;
cout"请输入新的姓名:";
cinp-name;
cout"请输入新的电话号码:";
cinp-tel;
}
p=p-next;
}
if(i==1) cout"修改成功!"endl;
if(i!=1) cout"未能找到。"endl;
return 1;
}
int List::dele()
{
person *q,*p=list;
char temp[20];
cout"你选择了根据姓名、电话删除信息。"endl"请输入将要删除的姓名或电话:";
cintemp;
if(p==NULL)
cout"为空或没有输入信息。"endl;
if(!strcmp(p-name,temp)||!strcmp(p-tel,temp)) //要删除的结点是第一个时
{
list=p-next;
delete p;
cout"删除成功!"endl;
}
else
{
while(p!=NULL(strcmp(p-name,temp)||strcmp(p-tel,temp)))
{
q=p;
p=p-next;
}
if(p==NULL) return 0;
else if(q==NULL)
cout"没能找到。"endl;
else
{
q-next=p-next;
delete p;
cout"删除成功!"endl;
}
}
return 1;
}
void main()
{
List L;
L.gncd();
}
求数据结构(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; i0; i--) // i is substring length
43 {
44 if (ix_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; kstrlen(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 }
数据结构c语言版源代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于数据结构 c语言中文网、数据结构c语言版源代码的信息别忘了在本站进行查找喔。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
相关推荐
- 05-12网页设计需要学什么,网页设计学什么语言
- 05-07pb超级报表源代码(pb报表工具)[20240507更新]
- 05-07简历源代码可以上传照片的简单介绍[20240507更新]
- 05-07广告切换源代码免费下载(广告切换源代码免费下载安装)[20240507更新]
- 05-06阁楼网源代码(阁楼是什么网站)[20240506更新]
- 05-06源代码管理资源管理器(资源管理器运行代码)[20240506更新]
- 05-06人脸识别源代码pdf的简单介绍[20240506更新]
- 05-06包含超市管理系统java源代码的词条[20240506更新]
- 05-06商城app源代码免费(商城App源码)[20240506更新]
- 05-06包含游戏源代码不同的模式的词条[20240506更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接