下面這個程式是在串列首的前面新增10次
這樣說不知道對不對= ="
#include
#include
struct Node
{
int data;
struct Node * pNext;
};
int main()
{
Node * pStart, * pCurrent, * pTmp;
pStart = pCurrent = pTmp = NULL;
for(int i=0; i<10; i++)
{
pTmp = new Node;
cin >> pTmp->data;
pTmp->pNext = pStart;
pStart = pTmp;
}
for (pCurrent = pStart; pCurrent!=NULL; pCurrent=pCurrent->pNext )
cout << pCurrent->data <
return 0;
}
然後我要把他改成在串列首的後面新增10次改不出來
只知道要把串列首的前面新增的程式加在前面,然後for跑9次新增
就是寫不出來...有人能幫忙改看看嗎...
2007-01-12 21:59:07 · 1 個解答 · 發問者 阿斯特卡 1 in 電腦與網際網路 ➔ 程式設計
如果不要用if else有辦法嗎?
2007-01-13 21:02:02 · update #1
#include
#include
struct Node
{
int data;
struct Node * pNext;
};
int main()
{
Node * pStart, * pCurrent, * pTmp;
pStart = pCurrent = pTmp = NULL;
for(int i=0; i<10; i++)
{
pTmp = new Node;
cin >> pTmp->data;
pTmp->pNext = NULL;
if (pCurrent == NULL)
{
pCurrent = pTmp;
pStart = pTmp;
}
else
{
pCurrent->pNext = pTmp;
pCurrent = pTmp;
}
// pTmp->pNext = pStart;
// pStart = pTmp;
}
for (pCurrent = pStart; pCurrent!=NULL; pCurrent=pCurrent->pNext )
cout << pCurrent->data <
return 0;
}
如果有問題, 請來函討論. 不然, 我可能會錯失你再補充的疑點.
2007-01-13 00:17:40 · answer #1 · answered by JJ 7 · 0⤊ 0⤋