#include //单链表的创建,插入,删除,打印 为什么没有输出数据呢?
#include
using namespace std;
typedef struct LNode
{
int num;
float score;
struct LNode next;
}LNode/*Linklist*/;
void CreateList_L(LNode *L,int n) //创建单链表
{
LNode *p;
L=new LNode;
L->next=NULL;
for(int i=n;i>0;i--)
{
p=new LNode;
cout<<"enter num score:"<
cin>>p->num>>p->score; //p.num 不对 为什么
p->next=L->next;
L->next=p;
}
}
int LinkInsert_L(LNode *L,int i, int num,float sco) //在单链表L中第i个位置之前插入元素
{
LNode *p;
p=L;
int j=0;
while(p&&j
{
p=p->next;
++j;
}
if(!p||j>i-1)return -1;
LNode *s=new LNode; //生成新节点
s->num=num;
s->score=sco;
s->next=p->next;
p->next=s;
}
int ListDelete_L(LNode *L,int i,int num,float sco) //在带头结点的单链表L中,删除第i个元素,并返回其值
{
LNode *p=L;
int j=0;
while(p->next&&j
{
p=p->next;
++j;
}
if(!(p->next)||j>i-1)return -1;
LNode *q=new LNode;
q=p->next;
p->next=q->next;
num=q->num;
sco=q->score;
free(q);
}
void print(LNode *L,int n) //输出打印单链表数据
{
LNode *p=L->next;
cout<<"Now,these "<<n<<" records are:"<<endl;
while(p!=NULL)
{
cout<<p->num<<" "<<p->score<<endl;
p=p->next;
}
}
int main()
{
void CreateList_L(LNode L,int n);
void print(LNode *L,int n);
const int m=3;
LNode l;
CreateList_L(l,m);
print(l,m);
return 0;
}