掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
Linked list (ID:58750)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
こんにちわw 今Linked Listを作ろうとしてるんですが、 表示がどうしても逆から表示されます。 なぜでしょうか? コードはしたです。 お願いします。 OS winXP Visual C++ #include <iostream> using namespace std; struct NODE{ int data; NODE *link; }; struct List{ NODE *head; NODE *pOld; int count; }; void printList(List list); int main(){ //リストの初期化 List list; int array[] = {3,6,12,4,2}; list.head = NULL; for(int i = 0 ; i < 5 ; i++){ //ノードの初期化 //ノードの初期化されたかチェック NODE *pNew; if(!(pNew = new NODE)){ return -1; } pNew->data = array[i]; pNew->link = list.head; list.head = pNew; list.count++; } printList(list); return 0; } void printList(List list){ int nodeNo; if(list.count == 0){ cout << "Nothing in list.\n" << endl; }else{ cout << "\ncontents of List" << endl; nodeNo=0; NODE *pWalk = list.head; while(pWalk){ cout << nodeNo << "\t" << pWalk->data << endl; pWalk = pWalk->link; nodeNo++; } } cout << "\nThere are " << nodeNo << " nodes in the list" << endl; }
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.