[問題] 一個ARRAY裡面有POINTER(DONE)
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
CODEBLOCK
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
struct data {
struct data *next ;
int number= 0 ;
int score = 0 ;
};
我想用這個struct 宣告成一個array 然後裡面有pointer 可以橫向的延伸
我一開始是這樣宣告
data dataA[i] ;
餵入的資料(Input):
預期的正確結果(Expected Output):
口->口
口->null
口->口->口
(以上是表示array 又能pointer 沒有限定資料)
錯誤結果(Wrong Output):
其中當我新增一筆資料的時候
EX我想把他加入index為3那裏
dataA[index].next=dataA[index] ;
這行就錯誤了
程式碼(Code):(請善用置底文網頁, 記得排版)
http://ideone.com/dO9o4d
是第94行的位置
如果要宣告的話 是否使用*data[i] ?
還是另有方法 ?
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.37.49.148
→
05/15 05:09, , 1F
05/15 05:09, 1F
→
05/15 10:39, , 2F
05/15 10:39, 2F
→
05/15 10:58, , 3F
05/15 10:58, 3F
→
05/15 12:34, , 4F
05/15 12:34, 4F
→
05/15 12:34, , 5F
05/15 12:34, 5F
→
05/15 12:34, , 6F
05/15 12:34, 6F
→
05/15 13:18, , 7F
05/15 13:18, 7F
→
05/15 13:19, , 8F
05/15 13:19, 8F
→
05/15 13:19, , 9F
05/15 13:19, 9F
→
05/15 13:20, , 10F
05/15 13:20, 10F
→
05/15 13:20, , 11F
05/15 13:20, 11F
→
05/15 13:22, , 12F
05/15 13:22, 12F
→
05/15 13:23, , 13F
05/15 13:23, 13F
假如我現在都是index = 1
我新增第二筆資料在index 1 裡面 會變成 新(2)->舊 (1)
但我在新增一筆資料在index 1 會變成 最新(3)-> (2)
然後最舊的那筆不見了
※ 編輯: redbxh 來自: 114.37.49.148 (05/15 13:28)
推
05/15 13:30, , 14F
05/15 13:30, 14F
→
05/15 13:30, , 15F
05/15 13:30, 15F
以解決
我後來修改了我的新增方式
新增之前 new 一個同struct 的pointer
然後再下去做新增
這是我在前一個學期就很常用的東西
竟然還要拿上來問大家
對不起
※ 編輯: redbxh 來自: 114.37.49.148 (05/15 13:48)