// test.cpp : å®ä¹æ§å¶å°åºç¨ç¨åºçå
¥å£ç¹ã
//
#include "stdafx.h"
// ç»æåémv
struct mv
{
int iv;
struct mv *p;
};
// æå°é¾è¡¨
void ListValue(mv * p)
{
while(p!=NULL)
{
printf("%d ",p->iv);
p = p->p;
}
printf("\n");
}
//æå
¥æ°å¼
void InsertValue(mv * p,int v1,int v2)
{
mv * p1 = NULL;
while(p!=NULL)
{
if(p->iv == v1)
{
if(p1==NULL) break;
mv *t = new mv;
t->iv = v2;
p1->p = t;
t->p = p;
break;
}
p1 = p;
p = p->p;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int iv = 0;
int count = 0;
mv *ph = NULL;
mv *pe = NULL;
while(iv >=0 && count<8)
{
printf("input a number:");
scanf("%d",&iv);
mv * vl = new mv;
vl->iv = iv;
if(ph == NULL)
ph = vl;
else
pe->p = vl;
pe = vl;
vl->p = NULL;
count++;
}
printf("vlue:");
ListValue(ph);
printf("\nAfter Insert New Value:");
InsertValue(ph,7,9);
ListValue(ph);
return 0;
}
![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/5ab5c9ea15ce36d3ce9b8ea63cf33a87e850b18c?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)