#include<stdio.h>
#include<stdlib.h>
typedef struct node{
int coef;
int exp;
struct node* next;
}NODE;
NODE* create(){
NODE* head = (NODE*)malloc(sizeof(NODE));
if(head!=NULL){
head->coef = 0;
head->exp = 0;
head->next = NULL;
}
return head;
}
NODE* Insert_head(int coef,int exp,NODE* head){
//NODE* tail = head;
NODE* newnode = (NODE*)malloc(sizeof(NODE));
if(newnode != NULL){
newnode->coef = coef;
newnode->exp = exp;
//头插法操作
newnode->next = head->next;
head->next = newnode;
return head;
}
}
NODE* Insert_tail(int coef,int exp,NODE* head){
NODE* tail = head;
while(tail->next != NULL){
tail = tail->next;
}
//尾插法
NODE* newnode = (NODE*)malloc(sizeof(NODE));
if(newnode != NULL){
newnode->coef = coef;
newnode->exp = exp;
newnode->next = tail->next;
tail->next = newnode;
tail = newnode;
return head;
}
}
void print_node(NODE* head){
NODE* print_node = head->next;
while(print_node != NULL){
printf("coef:%d,exp:%d->",print_node->coef,print_node->exp);
print_node = print_node->next;
}
}
NODE* add_list(){
}
int main()
{
NODE* A = create();
NODE* B = create();
int coef,exp;
printf("请输入数据:");
scanf("%d%d",&coef,&exp);
while(coef != 0){
A = Insert_tail(coef,exp,head);
scanf("%d%d",&coef,&exp);
}
scanf("%d%d",&coef,&exp);
while(){
B = Insert_tail(coef,exp,head);
scanf("%d%d",&coef,&exp);
}
print_node(head);
return 0;
}
05-26
264
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-13
07-13
07-13
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交