Javaコード:
パッケージコム; クラスA { パブリックintデータ。 公共A次= NULL; パブリックA(){ } 公共A(intデータ、次){ this.dataデータを=。 this.next =次回。 } } publicクラステスト{ 公共の静的な無効メイン(文字列[] args){ P =新しいA(0、NULL); ヘッド= P。 以下のために(INT I = 1; I <10; I ++){ E =新しいA(I、NULL); p.next = E; P = E; } ながら(!head.next = NULL){ のSystem.out.println(head.data)。 ヘッド= head.next。 } System.out.println(head.data)。 } }
結果: