天天看点

单链表实验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;