struct Number_Node
{
int number;
struct Number_Node* next_number;
};
int counter=0;
int main()
{
int input=0;
Number_Node* n;
Number_Node* h;
Number_Node* t;
do
{
cout << "Enter Number: ";
cin >> input;
n = new Number_Node;
n->number=input;
t=n;
if(counter==0)
{
h=n;
counter++;
}
t->next_number=n;
t=t->next_number;
n->next_number=NULL;
}while(input!=-1);
Number_Node *tmpPtr;
tmpPtr=h;
while(tmpPtr!=NULL)
{
cout << tmpPtr->number << endl;
tmpPtr=tmpPtr->next_number;
}
return 0;
}
这是我的代码,出于某种原因,只有第一个节点打印,然后事情结束。我在这里做错了什么?另外,将链表从低到高排序背后的想法是什么?