⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 12.txt

📁 Data Structure Question
💻 TXT
字号:
//多项式相加
#include <iostream.h>
#include <fstream.h>
#include <malloc.h>
#include <conio.h>
#define LE 0
typedef struct node_type{
    int count,exp;
struct node_type *next;
}link;
void main()
{
    int cn1,cn2;
link *h1,*h2,*h3,*p1,*p2,*p3,*q,*k;

p1=(link*)malloc(sizeof(link));
p2=(link*)malloc(sizeof(link));
h1=p1;
h2=p2;

//    char filename[18];
ifstream input;
// cout<<"Input filename:";
// cin>>filename;
// input.open(filename);
input.open("dxs.txt");

do{
input>>cn1>>cn2;
p1->count=cn1; p1->exp=cn2;
q=(link*)malloc(sizeof(link));
p1->next=q;
p1=q;
}while((cn1!=-1)||(cn2!=-1));
p1->count=0;
p1->exp=0;
p1->next=LE;

do{
input>>cn1>>cn2;
p2->count=cn1; p2->exp=cn2;
q=(link*)malloc(sizeof(link));
p2->next=q;
p2=q;
}while((cn1!=-1)||(cn2!=-1));
p2->count=0;
p2->exp=0;
p2->next=LE;

p1=h1;
p2=h2;
do
{
        cout<<p1->count<<" "<<p1->exp<<endl;
p1=p1->next;
}while(p1->next!=LE);

do
{
        cout<<p2->count<<" "<<p2->exp<<endl;
p2=p2->next;
}while(p2->next!=LE);

    p3=(link*)malloc(sizeof(link));
h3=p3;

p1=h1;
p2=h2;
do
{
    if(p1->exp>p2->exp)
{
    p3->exp=p1->exp;
p3->count=p1->count;
p1=p1->next;
q=(link*)malloc(sizeof(link));
p3->next=q;
p3=q;
}
    if(p2->exp>p1->exp)
{
    p3->exp=p2->exp;
p3->count=p2->count;
p2=p2->next;
q=(link*)malloc(sizeof(link));
p3->next=q;
p3=q;
}
if(p2->exp==p1->exp)
{
p3->exp=p1->exp;
p3->count=p1->count+p2->count;
p1=p1->next;
p2=p2->next;
q=(link*)malloc(sizeof(link));
p3->next=q;
p3=q;
}

}while(p1->next!=LE&&p2->next!=LE);
    p3->next=LE;

p3=h3;
do
{
k=p3->next;
if(k->next!=LE)
        cout<<"p3->count="<<p3->count<<" p3->exp="<<p3->exp<<endl;
p3=p3->next;
}while(p3->next!=LE);

cin>>cn1;

}
/*void shuru(void)
{
k=0;
do{
    k++;
input>>a[k]>>a1[k];
}while((a[k]!=-1)&&(b[k]!=-1));
k--;
}*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -