void printSList(slist *pList)
{
assert(pList);
if (pList == NULL)
return;
string str;
while (pList)
{
str = string(*pList) + str;
pList = pList->next;
}
printf("%s", str.c_str());
}
{
assert(pList);
if (pList == NULL)
return;
string str;
while (pList)
{
str = string(*pList) + str;
pList = pList->next;
}
printf("%s", str.c_str());
}
遞歸:
void printSList(slist *pList)
{
assert(pList);
if (pList == NULL)
return;
if (pList->next == NULL)
printf("%s", *pList);
else
{
printSList(pList->next);
printf("%s", *pList);
}
}
{
assert(pList);
if (pList == NULL)
return;
if (pList->next == NULL)
printf("%s", *pList);
else
{
printSList(pList->next);
printf("%s", *pList);
}
}
分配一個(gè)數(shù)組,把指針放到數(shù)組中,然后for倒著打印
Status display(LinkList &L)
{
printf("\n---------------------------顯示單鏈線性表----------------------\n");
LinkList p;
int n[100];
int j=100;
p=L->next; //打印的時(shí)候應(yīng)該從頭結(jié)點(diǎn)的下一個(gè)結(jié)點(diǎn)開始打印,否則會(huì)出現(xiàn)亂碼
printf("\n單鏈表為:\t");
if(p!=NULL)
{
for(;p!=NULL;--j)
{
n[j-1]=p->date; //j-1是因?yàn)?00要存放頭結(jié)點(diǎn)的位置
p=p->next;
}
for(;j<100;j++)
{
printf("%d",n[j]);
}
}
free(p);
return 1;
}//display


