天天看點

單連結清單實驗java_JAVA連結清單實驗

#include

#include

#include

#include

using namespace std;

struct Node

{

float coef;

int exp;

struct Node *next;

};

//typedef struct tagNode Node;

void creatListHead(int m,struct Node *head)

{

struct Node *p=NULL;//臨時使用

int n=0;

int exp;

float coef;

cout<

cout<

cin>>coef;

cout<

cin>>exp;

while(0==0)

{

//配置設定空間,指派

n++;

if(n==m)break;

p=(struct Node*)malloc(sizeof(struct Node));

p->exp=exp;

p->coef=coef;

p->next=head->next;//對next域的指派很容易忘記

head->next=p;

cout<

cin>>coef;

cout<

cin>>exp;

}

}

/*void inputlink(int m,int n,struct Node *pa,struct Node *pb) {

Node *p1=(Node*)malloc(sizeof(struct Node));

Node *p1=pa->next;