📄 ds1.cpp
字号:
// DS1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdlib.h"
#include "iostream.h"
typedef struct node
{
float coe;
struct node * link;
};
node* creatp(int N)
{
node* h,*s,*p;
h=(node*)malloc(sizeof(node*));
h->coe=-99.0f;
h->link=NULL;
p=h;
for (int i=0;i<N;i++)
{
s=(node*)malloc(sizeof(node*));
p->link=s;
s->link=NULL;
p=s;
}
return h;
}
void coe(node* coe,float *c)
{
coe=coe->link;
while(*c&&coe!=NULL)
{
coe->coe=*c;
coe=coe->link;
c++;
}
}
void show(node* h)
{
h=h->link;
while(h)
{
cout<<"coe:"<<h->coe<<endl;
h=h->link;
}
}
void add(node* h1,node* h2)
{
h1=h1->link;
h2=h2->link;
while(h1)
{
h1->coe+=h2->coe;
h1=h1->link;
h2=h2->link;
}
}
int main(int argc, char* argv[])
{
node *h1;
h1=creatp(4);
float *c1=new float[4];
c1[0]=1.0f;
c1[1]=2.0f;
c1[2]=3.0f;
c1[3]=4.0f;
coe(h1,c1);
node *h2;
h2=creatp(4);
float *c2=new float[4];
c2[0]=2.0f;
c2[1]=3.0f;
c2[2]=4.0f;
c2[3]=5.0f;
coe(h2,c2);
show(h1);
show(h2);
add(h1,h2);
show(h1);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -