资源简介
使用链表实现多项式的加法和乘法,数据结构常见问题的C语言实现
代码片段和文件信息
#include
#include
#include
typedef struct list
{
int xishu;
int power;
struct list *next;
}list;
list* creat()
{
list* head=(list*)malloc(sizeof(list));
if(head==NULL)
{
printf(“malloc head node failed\n“);
exit(-1);
}
head->xishu=0;
head->power=0;
head->next=NULL;
int count;
printf(“please input the count of the list:“);
scanf(“%d“&count);
printf(“please input %d xiangwith the power increase\n“count);
while(count<=0)
{
printf(“the input is invalidplease input the count of the list again:“);
scanf(“%d“&count);
}
while(count>0)
{
list *newnode=(list*)malloc(sizeof(list));
if(newnode==NULL)
{
printf(“malloc newnode failed\n“);
exit(-1);
}
printf(“please input xishu:“);
scanf(“%d“&newnode->xishu);
printf(“please input power:“);
scanf(“%d“&newnode->power);
newnode->next=head->next;
head->next=newnode;
--count;
}
return head;
}
void print(const list* lst)
{
if(lst==NULL)
printf(“the list is not exist\n“);
if(lst->next!=NULL)
{
list *p=lst->next;
while(p!=NULL)
{
if(p->power!=0&&p->xishu!=1&&p->power!=1)
printf(“%dX^%d“p->xishup->power);
else if(p->power!=0&&p->xishu!=1&&p->power==1)
printf(“%dX“p->xishu);
else if(p->power!=0&&p->xishu==1&&p->power!=1)
printf(“X^%d“p->power);
else if(p->power==1&&p->xishu==1)
printf(“X“);
else
printf(“%d“p->xishu);
p=p->next;
if(p!=NULL)
printf(“+“);
}
printf(“\n“);
}
}
void list_free(list *a)
{
if(a==NULL)
return ;
list *pa=a->next;
while(pa!=NULL)
{
list *tmp=pa;
pa=pa->next;
free(tmp);
tmp=NULL;
}
free(a);
a=NULL;
}
list *list_copy(const list *src)
{
if(src==NULL)
{
printf(“the list is not exist\n“);
exit(-1);
}
const list *p=src->next;
list* head=(list*)malloc(sizeof(list));
if(head==NULL)
{
printf(“malloc head node failed\n“);
exit(-1);
}
head->xishu=0;
head->power=0;
head->next=NULL;
list* place=head;
while(p!=NULL)
{
list *newnode=(list*)malloc(sizeof(list));
if(newnode==NULL)
{
printf(“malloc newnode failed\n“);
exit(-1);
}
newnode->xishu=p->xishu;
newnode->power=p->power;
相关资源
- 利用C++哈希表的方法实现电话号码查
- 学校超市选址问题(数据结构C语言版
- 数据结构,迷宫问题C语言版源代码
- DSDEMO-C演示(数据结构C语言版 严蔚敏
- 数据结构 图的遍历源代码
- 数据结构实验源代码集
- 实验报告:数据结构长整数四则运算
- 数据结构教程李春葆第五版书中例题
- 吕鑫vc6c++数据结构视频源码
- 数据结构教程李春葆第五版课后答案
- 李春葆课后习题答案(数据结构教材
- 数据结构1800题 题+答案(全)
- 数据结构(C语言版)ppt课件,清华,
- c++常用游戏算法及数据结构设计
- 数据结构超全面复习导图
- 《Data Structures and Algorithm Analysis in C
- 数据结构C语言版教学笔记严蔚敏
- 数据结构C语言版期末考试试题(有答
- 多功能计算器实现C++代码以及代码详
- C语言数据结构银行客户排队
- C语言实现栈操作
- 简易学生管理系统源码 数据结构 大作
- 数据结构与C语言综合习题集
- 数据结构实验——赫夫曼树相关
- C语言进阶源码---基于graphics实现图书
- 数据结构——C++语言描述 陈慧南
- 广东工业大学数据结构课程设计航空
- 数据结构课程设计扑克牌排序
- 数据结构各种算法实现(C++模板),
- (严版C语言版数据结构源码.rar
评论
共有 条评论