轉自:http://www.shnenglu.com/humanchao/archive/2008/02/29/43446.html
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());
}
遞歸:
void printSList(slist *pList)
{
assert(pList);
if (pList == NULL)
return;
if (pList->next == NULL)
printf("%s", *pList);
else
{
printSList(pList->next);
printf("%s", *pList);
}
}
分配一個數組,把指針放到數組中,然后for倒著打印
Status display(LinkList &L)
{
printf("\n---------------------------顯示單鏈線性表----------------------\n");
LinkList p;
int n[100];
int j=100;
p=L->next; //打印的時候應該從頭結點的下一個結點開始打印,否則會出現亂碼
printf("\n單鏈表為:\t");
if(p!=NULL)
{
for(;p!=NULL;--j)
{
n[j-1]=p->date; //j-1是因為100要存放頭結點的位置
p=p->next;
}
for(;j<100;j++)
{
printf("%d",n[j]);
}
}
free(p);
return 1;
}//display
posted on 2012-04-09 16:41
王海光 閱讀(752)
評論(0) 編輯 收藏 引用 所屬分類:
算法