Óû§Ãû£ºwtoe5820
ÓÃÁ´±í´æ**
°´³É¼¨ÅÅÐò
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
typedefintElemType;
typedefstructLNode{
ElemType**mber;
ElemTyperesult;
½Ó´ú¼Ó¶àstructLNode*neÀ´×Ôxt;
}linklist,*link;
/*¹¹ÔìÁ´±í*///////ÁùÔç///////////////////////////////
voidIinitList(link&L)
{
if(L)deleteL;
L=(link)malloc(sizeof(LNode));
if(!L)exit(1);
L->next=**LL;
cout<<"**ÒѾ½¨Á¢\n";
}
/////////////////////////////////////////////////////
////*ÏÔʾ***/////////////////////////////////////////
voidÎÊ´ðshow(linkl)
{linkp;intj;
p=l;jûµ°µô¼ûºâ´¹ÑÎÖð=0;
cout<<"±¾°üÖ°×Ó°´Õæ¶û¾Ý**µÄֵΪ£º\n";
while(p->next)
{
cout<<p->nex×ßУÌÖ¸èÓëºâ½ñÒª½Õ²¼t->**mber<<""<<p->next->result<<endl;
ÂÞËßij²é¼äÎÞÖ´¹¹¹¹p=p->next;
Èë}
}
/////////////////////////////////////////////////////////
//////Ïú»ÙÁ´±í//////////////////////////////////////////////
voiddestorylinst(link&L)
¾°Á¢Í³²âºú¾Ù¸ü{
while(LÈ«)
{linkp=L;
L=L->next;
free(p¿ËÀºÚÐĽâ);
}
L=**LL;
}
//////////////////////////////////////ά½é¼þÏûæÃάɽ̫Ïç////////////Òôɱ»ù¹ÊÄêÒÕ¶¼Ôð¼õ/////
///*²åÈë½áµã½«ÈõÌå¼´ÀÏËÉÌýתºñ*//////////////////////////////////////
intlistinsert(link&L,in·¸ÈôËüÃÀ°Ù¶øÖ§Ãçti,ElemTypenum,ElemTyperes)
{
linkpίÈÝËê·**èÂð,q;
intj;
p=L;j=0;
while(p&&j<i-1)
{
p=p->next;++j;
}
q=(linÌØ°ü²ÆÄÚË¿»õk)malloc(sizeof(LNode));
×îºÁÆÈq->**mber=**m;
Öι¹¹æÂÔq->result=res;
q->next=p->next;
p->next=q;cout<<"**ÒѾ²åÈë\n";cout<<"----------\n";
return1;
}
//////´òÓ¡±íÍ·///////////////////////////////////////
voidprint()
{
cout<<"------------------------\n";
cout<<"------------------------\n";
}
voidputline(link&l)
{
if(l==**LL||l->next==**LL)
cout<<"**Ϊ¿Õ£¬ÇëÏȽ¨Á¢\n";
else{
linkp,q;
p=l->next;
while(p!=**LL)
{
q=p->next;
while(q!=**LL)
{
if(p->result<q->result)
{ElemTypet1,t2;
t1=p->**mber;
t2=p->result;
p->**mber=q->**mber;
p->result=q->result;
q->**mber=t1;
q->result=t2;
}
q=q->next;
}
p=p->next;
}cout<<"ÒѾ°´³É¼¨ÅÅÐò\n";
}
}
/////////////////////////////////////////////////
///////////////////////////////////////////////////
//////²âÊÔº¯Êý//////////////////////////
voidmain()
{linkL=**LL;intk;
while(1)
{
cout<<"°´0Í˳ö³ÌÐò\n"<<"°´1½¨Á¢³É¼¨¼Ç¼\n"
<<"°´2½øÐÐÅÅÐò\n";
print();
inta,i,j;
cin>>a;
switch(a)
{
case0:if(L!=**LL)
destorylinst(L);
exit(1);
case1:
IinitList(L);
k=0;
show(L);
cout<<"**Ϊ¿Õ\n";
cout<<"ѧÉúÈËÊýΪ:"<<k<<endl;
print();
cout<<"ÇëÊäÈëѧºÅºÍ³É¼¨£¬Ñ§ºÅºÍ³É¼¨ÊäÈëΪ0ʱ½áÊø\n";
int**mber,result;
cout<<"ÊäÈëѧºÅ£º";
cin>>**mber;
cout<<"ÊäÈë³É¼¨";
cin>>result;
while(**mber!=0)
{k++;
listinsert(L,k,**mber,result);
cout<<"ÊäÈëѧºÅ£º";
cin>>**mber;
cout<<"ÊäÈë³É¼¨";
cin>>result;
}
print();
show(L);cout<<"ѧÉúÈËÊý:"<<k<<endl;
print();
bre**;
case2:
putline(L);
if(L!=**LL)
show(L);
print();
bre**;
default:
bre**;
}
}
deleteL;
}