我有兩個命令「add」和「undo」。使用「添加」操作,可以將多對(包括一對)發送到該程序。另一方面,使用「撤消」操作,應該返回最後發送的數據。爲了實現這個功能,我想到了;如何確保所有容器中的第一個鍵在整個堆棧中都是唯一的
我應該有這些元素的數據結構;
| | HashMap<String, String> : It is used for storing data
| |
| |
| |
--------
Stack : It seems best to "undo" and "add" operations.
在某些時候,我應該在實踐中,有如下堆棧;
| |
| |
| ________________________________ |
| | (filename5, date1) | | third HashMap type container
| | (filename6, date5) | | holding three items
| | (filename7, date9) | |
| |______________________________| |
| |
| ________________________________ | second HashMap type container
| | (filename3, date2) | | holding one item
| |______________________________| |
| |
| ________________________________ | first HashMap type container
| | (filename1, date1) | | holding two items
| | (filename2, date2) | |
| |______________________________| |
|----------------------------------|
我的問題是「我怎樣才能確保第一項中的所有容器中整個堆棧是獨特?」
如果上述數據結構不可能實現,那麼我應該如何使用這個數據結構來實現上述的願望?
你試圖避免什麼。有兩個'filename1'? – SJuan76 2014-09-04 10:18:19
@ SJuan76我試圖避免dublicate兩個條目,如堆棧中的文件名。對於文件名的情況下,我不希望讓用戶選擇相同的文件名兩次。如果我讓,整個堆棧可以填充,例如(filename1,date1),(filename2,date3),(filename1,date1),(filename2,date3)... – Hevan 2014-09-04 10:23:00