c语言数据结构源码
❶ 数据结构:产品进销存管理系统的源代码(c语言或c++的)
&(p->salesquantity),&(p->salestime).year),&((p->salestime).month),&((p->salestime).day)); p->nextproct=q->nextproct;
q->nextproct=p;
q=p
}
}
return ok;
}//ProctInsert
void ProQuantity_add(sqmountlink&L,char pkindname 1[],char pname 1[],int n)
{//添加顺序表挂接链表的某产品的总量,且需添加的产品总量为n
int i,k;
plinklist p;
for(i=0;i<L.length;i++)
{
if(strcmp(L.kindelem[i]).pkindname,pkindname 1)!=0)
continue;
else
break;
}
if(i<L.length)
{
for(p=L.kindelem[i].firstproct;p!=NULL;p=p->nextproct)
{
k=strcnp(p->pname.pname);
if(k==0)
{
p->totalquantity=p->totalquantity+n;
printf("查看添加后产品的各项输出:%s %d%d,%d %d %d,%d,%d\n",p-pname,p->totalquantity,(p->goodsdate).year,(p->goodsdate).month,(p->goods).day,
p->salequanlity,(p->salestime).year,(p->salestime).month,(p->salestime).day);
}
}
}
}//ProQuantity_add
void Visit(sqmountlink&L,char pkindname3[],char pname3[])
{//在顺序表挂接链表L中,查询属于某产品类的某产品的各项信息
int i,k;
plinklist p;
for(i=0;i<L.length;i++)
{
if(strcmp((L.kindelem[i]),pkindname.pkindname3)!=0)
continue
else
break;
}
if(i<L.length)
{
for(p=L.kindelem[i].firstprodicy;p!=NULL;p=p->nextprocy)
{
k=strcmp(p->pname.pname3);
if(k==0)
break;
}
if(k!=0)
printf("此产品不存在:\n")
else
{
printf("输出带查询产品的各项信息:\n");
printf("%s %s %d %d,%d,%d %d %d,%d,%d\n",(L.kindelem[i]).pkindname,p->pname,p->totalquantity,(p->goodsdate).year,(p->goodsdate).month,(p->goodsdate).day,
p->salequantity,(p->salestime).year,(p->salestime).month,(p->salestime).day);
}
}
}//Visit
void DisplayList(sqmountlink&L)
{//显示各产品所属产品类,产品名称、产品总量,进货日期,销出数量,销售时间
int i;
plinklist p;
printf("产品类 产品 进货日期 销出数量 销售时间\n")
for(i=0;i<L.length;i++)
{
if(!(L.kindelem[i],firstproct))
printf("%s\n",(L.kindelem[i]).pkindname);
for(p=L.kindelem[i].firstproct;p;p=p->nextproct)
printf("%s %s %d %d,%d,%d %d %d,%d,%d \n",(L.kindelem[i]).pkindname,p->pname,p->totalquantity,(p->goodsdate).year,(P->goodsdate).month,(p->goodsdate).day,p->salesquantity,(p->salestime).year,(p->salestime).month,(p->salestime).day);
}
}//DisplayList
void DestoryMountList(sqmountlink&L)
{//销毁已存在的顺序表挂接链表L
int i;
kindlnode *p;
for(i=L.length;i>=0;
{
p=&(L.kindelem[i]);
if(*p).firstproct==NULL)
free(p);
else
{
while((*p).firstproct;q->nextproct;q=q->nextproct);
free(q);
}
free(q);
}
}
}//DestroyMountList
void menu_operation()
{//操作菜单
printf("----输入所要执行操作:-------\n")
printf("----产品类的添加:1------\n");
printf("----产品的添加:2-----\n");
printf("----产品数量的添加:3-----\n");
printf("----查询每种产品所属产品类,产品总量,进货日期,销出数量,销售时间:4-----------\n")
printf("----释放L所占内存空间,退出程序:0-----\n");
}//menu_operation
/*--------------主程序-------------*/
void main(void)
{
int order,
int i,n;
char a[30];
char b[30];
sqmountlink L;
InitMountList(L);
printf("-----创建初始的产品类、产品顺序表挂接链表L-----\n");
CreatMuntList(L);
DisplayList(L);
printf("-----初始的产品类、产品顺序表挂接链表L创建完成-----\n");
menu_operation();
loop:
printf("输入命令:");
scanf("%d",&order);
switch(order)
{
case 1:
printf("需添加产品类的个数:");
scanf("%d",&i);
kindinsert(L,i);
printf("输出修改后的产品库存管理表:\n");
DisplayList(L);
goto loop;
case 2:
printf("需添加产品所属产品类的名称:")
scanf("%s",&a);
printf("需向此产品类添加产品的个数:");
scanf("%d",&i);
ProctInsert(L,a,i);
printf("输出修改后的产品库存管理表:\n");
DisplayList(L);
goto loop;
case 3:
printf("输入需添加数量的产品所属产品类的名称:");
scanf("%s",&a);
printf("输入需添加数量的产品的名称:");
scanf("%d",&n);
ProQuantity_add(L,a,b,n);
printf("输出修改后的产品库存管理表:\n");
DisplayList(L);
goto loop ;
case 4:
printf("输入待查询产品所属产品类的名称:");
scanf("%s",&b);
printf("输入待查询产品的名称:");
scanf(%s",&b);
Visit(L<a,b);
goto loop;
case ():
DestroyMountList(L);
exit(0);
}
}
❷ c语言题型,数据结构题
#include <stdio.h>
#include <malloc.h>
typedef struct student
{
char name[20];
long num;
char sex;
struct student *pNext;
}Stu, *pStu;
void creatInfo(pStu *stu);
int deletInfo(pStu stu, long numTemp);
void printInfo(pStu stu);
int main(void)
{
long numTemp = 0;
pStu myStu = NULL;
creatInfo(&myStu);
scanf("%ld", &搏御numTemp);
if(1 == deletInfo(myStu, numTemp))
printInfo(myStu);
return 0;
}
void creatInfo(pStu *stu)
{
int n = 1;
pStu pNew = NULL, pTail = NULL;
*stu = (pStu)malloc(sizeof(Stu));
if(*stu == NULL)
return ;
(*stu)->pNext = NULL;
pTail = *stu;
while(n <= 10)
{
pNew = (pStu)malloc(sizeof(Stu));
if(NULL == pNew)
return ;
pNew->pNext = NULL;
scanf("%s", pNew->name);
if('#' == pNew->name[0])
{
free(pNew);
pNew = NULL;
return ;
}
scanf("%ld %c", &pNew->num, &pNew->sex);
pTail->薯行pNext = pNew;
pTail = pNew;
++n;
}
}
int deletInfo(pStu stu, long numTemp)
{
pStu pTail = NULL, pHead = NULL;
pHead = stu;
pTail = stu->pNext;
while(pTail)
{
if(pTail->num == numTemp)
{
pHead->pNext = pTail->pNext;
free(pTail);
pTail = NULL;
return 1;
}
pTail = pTail->pNext;
pHead = pHead->pNext;
}
printf("链表中唔基手岩该学生! ");
return 0;
}
void printInfo(pStu stu)
{
while(stu = stu->pNext)
printf("%s, %d, %c ", stu->name, stu->num, stu->sex);
}
❸ 数据结构C语言版冒泡排序的程序和应用,谁能帮我写一个。
这是一个C语言实现的冒泡排序程序,用于对数组中的数据进行排序。以下是程序代码:
首先,定义一个数组a,大小为10,用于存放数据。通过for循环,输入10个数据到数组中。
接着,使用冒泡排序算法对数组进行排序。通过两层for循环,外层循环控制比较的轮数,内层循环控制每一轮比较的元素。
在内层循环中,如果当前元素大于其后一个元素,就交换它们的位置。经过多次比较和交换,最终实现数组的排序。
排序完成后,通过for循环输出排序后的数组。使用printf函数输出数组中的每一个元素,并使用空格分隔。
最后,调用system("PAUSE")函数,使程序暂停,等待用户输入,以便查看输出结果。
通过运行上述程序,可以对任意长度为10的数据数组进行排序。例如,输入一组随机数据,程序将对它们进行排序,并输出排序后的结果。
冒泡排序是一种简单的排序算法,通过不断地交换相邻元素,使得较小的元素逐渐向数组的前端移动,实现数组的排序。它适用于小规模数据的排序,但在处理大规模数据时效率较低,因为它的时间复杂度为O(n^2)。
冒泡排序在实际应用中主要用于教学和示例,因为它易于理解和实现。在实际的开发中,通常会使用更高效的排序算法,如快速排序、归并排序等。
❹ c语言数据结构
#include<stdio.h>
#include<malloc.h>
#include<string.h>
struct student{ int age; char name[10]; struct student *next; } ;
void main() { struct student *p,*p1,*p2;
p1=(struct student *)malloc(sizeof(struct student)); if ( p1==NULL ) goto errorexit0;
strcpy(p1->name,"张三"); p1->age=30; p1->next=NULL;
p2=(struct student *)malloc(sizeof(struct student)); if ( p2==NULL ) goto errorexit1;
strcpy(p1->name,"李四"); p2->age=40; p2->next=NULL;
p=p1; p->next=p2;
printf("%s %s\n",p->name,(p->next)->name);
free(p1); free(p2); return;
errorexit1: free(p1); printf("申请节点2出错。\n");
errorexit0: printf("申请节点1出错。\n");
}
❺ 求100行左右的代码(C语言,c++,数据结构编写的均可)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 10
struct library {
int num;
char book_name[30];
char writer[30];
char sort_num[3];
char pub_company[30];
char pub_time[30];
char prise[30];
};
typedef struct library LIB; /*结构体的定义用于存放书籍及借书的信息*/
LIB lib[N];
FILE *fp; int all=0;
int menu(void);
void input(void);
void output(void);
void save(void);
void del(void);
void search(void);
void xiugai(void);
main()
{
for(;;)
{
switch(menu()) {
case 1:input();break;
case 2:output();break;
case 3:save();break;
case 4:search();break;
case 5:xiugai();break;
case 6:del();break;
case 7:sort();break;
case 0:exit(1);break;
} /*SWITCH定义函数输出*/
}
}
int menu(void)
{
char m[3];
int n; printf(" *********************WELCOME**********************\n\n\n\n\n");
printf("\t\t\t-----图书信息管理系统----\n");
printf("\t\t1:输入\n");
printf("\t\t2:输出\n");
printf("\t\t3:保存\n");
printf("\t\t4:查找\n");
printf("\t\t5:修改\n");
printf("\t\t6:删除\n");
printf("\t\t7:统计\n");
printf("\t\t0:退出\n");
printf("\t\tplease choose a operation(0-6):\n");
scanf("%s",m);
n=atoi(m);
return(n);
} /*主要界面*/
void input(void)
{
int i;
char m[3];
for(i=all;i<N;i++)
{
all++;
printf("请输入信息:\n");
printf("\t\t号码:\n");
scanf("%d",&lib[i].num);
printf("\t\t书名:\n");
scanf("%s",lib[i].book_name);
printf("\t\t作者:\n");
scanf("%s",lib[i].writer);
printf("\t\tsort_num:\n");
scanf("%s",lib[i].sort_num);
printf("\t\t出版商:\n");
scanf("%s",lib[i].pub_company);
printf("\t\t出版时间:\n");
scanf("%s",lib[i].pub_time);
printf("\t\t价格:\n");
scanf("%s",lib[i].prise);
a: printf("\t\tyes/哦了?\n");
printf("\t\t1:yes\n");
printf("\t\t2:no\n");
scanf("%s",m);
if(atoi(m)==1)
continue;
else if(atoi(m)==2)
return;
else
{
printf("\t\t错误!\n");
goto a;
} /* 输入条件查找*/
}
}
void output(void)
{
int i;
for(i=0;i<all;i++)
{
printf("\t\t%d\n",lib[i].num);
printf("%s\t\t%s\t\t%s\n",lib[i].book_name,lib[i].writer,lib[i].sort_num);
printf("%s\t\t%s\t\t%s\n",lib[i].pub_company,lib[i].pub_time,lib[i].prise);
}
} /*输出书名作者出版时间价格等*/
void save(void)
{
int i;
if((fp=fopen("file.c","wb"))==NULL)
{
printf("can not open the file");
exit(1);
}
for(i=0;i<all;i++)
{
if(fwrite(&lib[i],sizeof(LIB),1,fp)!=1)
{
printf("can not write!");
exit(1);
}
} /*条件不符合时拒绝存储*/
fclose(fp);
}
void search(void)
{
int i,flag;
char m[3];
char name[30];
printf("\t\t请选择您的存储方式:\n");
printf("\t\t1:按书名!\n");
printf("\t\t2:按作者!\n");
scanf("%s",m);
i=atoi(m);
switch(i)
{
case 1:{
printf("\t\t请输入书名:\n");
scanf("%s",name);
flag=0;
for(i=0;i<N;i++)
{
if(strcmp(name,lib[i].book_name)==0)
{
printf("\t\t%d\n",lib[i].num);
printf("%s\t\t%s\t\t%s\n",lib[i].book_name,lib[i].writer,lib[i].sort_num);
printf("%s\t\t%s\t\t%s\n",lib[i].pub_company,lib[i].pub_time,lib[i].prise);
flag=1;break;
}
}
if(flag==0)
printf("\t\t没有这本书!\n");
}
case 2:{
printf("\t\t请输入作者:\n");
scanf("%s",name);
flag=0;
for(i=0;i<N;i++)
{
if(strcmp(name,lib[i].writer)==0)
{
printf("\t\t%d\n",lib[i].num);
printf("%s\t\t%s\t\t%s\n",lib[i].book_name,lib[i].writer,lib[i].sort_num);
printf("%s\t\t%s\t\t%s\n",lib[i].pub_company,lib[i].pub_time,lib[i].prise);
flag=1;break;
}
}
if(flag==0)
printf("\t\t没有这个作者!\n");
}
} /*查找图书按书名或作者并输出*/
}
void xiugai(void)
{
int i,flag;
char name[30],n[3];
printf("\t\t请输入要修改的书名 :\n");
scanf("%s",name); /*修改书名*/
flag=0;
for(i=0;i<N;i++)
{
if(strcmp(name,lib[i].book_name)==0)
{
printf("\t\t%d\n",lib[i].num);
printf("%s\t\t%s\t\t%s\n",lib[i].book_name,lib[i].writer,lib[i].sort_num);
printf("%s\t\t%s\t\t%s\n",lib[i].pub_company,lib[i].pub_time,lib[i].prise);
printf("\t\tplease input xiugai's the informations:\n");
printf("\t\tnum:\n");
scanf("%d",&lib[i].num);
printf("\t\tbook_name:\n");
scanf("%s",lib[i].book_name);
printf("\t\twriter:\n");
scanf("%s",lib[i].writer);
printf("\t\tsort_num:\n");
scanf("%s",lib[i].sort_num);
printf("\t\tpub_company:\n");
scanf("%s",lib[i].pub_company);
printf("\t\tpub_time:\n");
scanf("%s",lib[i].pub_time);
printf("\t\tprise:\n");
scanf("%s",lib[i].prise);
flag=1;break;
}
} /*增加图书*/
if(flag==0)
printf("\t\t没有找到啊!\n");
}
void del(void)
{
int i,j,flag;
char name[30];
printf("\t\t请输入要删除的书名:\n");
scanf("%s",name);
flag=0;
for(i=0;i<N;i++)
{
if(strcmp(name,lib[i].book_name)==0)
{
printf("\t\t%d\n",lib[i].num);
printf("%s\t\t%s\t\t%s\n",lib[i].book_name,lib[i].writer,lib[i].sort_num);
printf("%s\t\t%s\t\t%s\n",lib[i].pub_company,lib[i].pub_time,lib[i].prise);
for(j=N;j>i;j--)
{
lib[j-1].num=lib[j].num;
strcpy(lib[j-1].book_name,lib[j].book_name);
strcpy(lib[j-1].writer,lib[j].writer);
strcpy(lib[j-1].sort_num,lib[j].sort_num);
strcpy(lib[j-1].pub_company,lib[j].pub_company);
strcpy(lib[j-1].pub_time,lib[j].pub_time);
strcpy(lib[j-1].prise,lib[j].prise);
flag=1;
printf("\t\t已经删除!\n");
break;
}
}
}
if(flag==0)
printf("\t\t没有这本书!\n");
} /*删除图书*/
❻ 急求通讯录管理系统(有链表的)数据结构c语言版的源代码。要求c++可以测试通过
这个绝对满足了你的要求了,谢谢采纳`
#include<iostream.h>
#include<string>
#include<stdlib.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;
cin>>a;
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->name<<endl;
cout<<"电话:"<<p->tel<<endl;
p=p->next;
}
cout<<endl;
return 1;
}
int List::append()
{
person *p=new person;
cout<<"请输入姓名:"<<endl;
cin>>p->name;
cout<<"请输入电话号码:"<<endl;
cin>>p->tel;
char temp;
cout<<"是否继续输入(y/n)";
cin>>temp;
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<<"请输入将要修改的姓名或电话:";
cin>>temp;
int i=0;
while(p!=NULL)
{
if(!strcmp(p->name,temp)||!strcmp(p->tel,temp))
{
i=1;
cout<<"请输入新的姓名:";
cin>>p->name;
cout<<"请输入新的电话号码:";
cin>>p->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<<"请输入将要删除的姓名或电话:";
cin>>temp;
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();
}