入力が空白になるまでユーザーから単語を取得するリンクされたリストを作成しようとしています。すべての単語が追加されるため、リストはアルファベット順に表示されます。ただし、最初のノードのみが出力されます。私が間違っていることはありますか?これが私が持っているものです(ヘッダーと宣言を除く):
//put in additional nodes until the input is blank
while(in != " "){
cin >> in;
newPtr->data = in;
prevPtr->data = "";
prevPtr->next = NULL;
nextPtr = list;
//shift the prevPtr and nextPtr until newPtr is alphabetically between them
while(!(prevPtr->data<=in && nextPtr->data>in)){
prevPtr = nextPtr;
nextPtr = prevPtr->next;
}
//make newPtr point to the next node
if(nextPtr != NULL){
newPtr->next = nextPtr;
}
//make newPtr the "next" pointer of the previous node, if any
if(prevPtr != NULL){
prevPtr->next = newPtr;
}
//if there's nothing before newPtr, make it the first node
else{
list = newPtr;
}
printList(list);
};
}