找回密碼 或 安全提問
 註冊
|註冊|登錄

伊莉討論區

搜索
請尊重及感激所有版主付出和奉獻感激所有對伊莉作出奉獻的人尊貴會員無限下載附件
三上悠亜偷拍fate中出按摩國中kkbox
敗北無碼rpgアメイジ異世界パ百鮑看盡多空@

休閒聊天興趣交流學術文化旅遊交流飲食交流家庭事務PC GAMETV GAME
熱門線上其他線上感情感性寵物交流家族門派動漫交流貼圖分享BL/GL
音樂世界影視娛樂女性頻道潮流資訊BT下載區GB下載區下載分享短片
電腦資訊數碼產品手機交流交易廣場網站事務長篇小說體育運動時事經濟
上班一族博彩娛樂

(4月新番)[繁]無職轉

(4月新番)[繁]怪獸八

(4月新番)[繁]怪異與

[繁]轉生貴族憑鑑定技

[繁]怪物轉生 Re:Mons

(4月新番)[繁]神明渴
C & C++ 語言C# 語言Visual Basic 語言PHP 語言JAVA 語言
查看: 1784|回復: 4
打印上一主題下一主題

[作業]用XOR的概念,實作doubly linked list。[複製鏈接]

ycess87009 該用戶已被刪除
跳轉到指定樓層
樓主
發表於 2012-11-11 12:11 AM|只看該作者|倒序瀏覽
本帖最後由 ycess87009 於 2012-11-11 12:15 AM 編輯

XOR的意思:如果 i=10110,j=01100,i XOR j=11010。
作業規定:
利用課本提供的方法,實作doubly linked list
每個node的structure包含一個data,一個link。

作業輸出和輸入的範例如下:
Choice 1)insert 2)show list : 1
input sequence : 1 2 6 9 3 15
Choice 1)insert 2)show list : 2
Left to Right : 1 2 6 9 3 15
...
瀏覽完整內容,請先 註冊登入會員
附件: 你需要登錄才可以下載或查看附件。沒有帳號?註冊
分享分享0收藏收藏0支持支持0
成為伊莉的版主,你將獲得更高級和無限的權限。把你感興趣的版面一步步地發展和豐盛,那種滿足感等著你來嚐嚐喔。

使用道具檢舉

ycess87009 該用戶已被刪除
頭香
發表於 2012-11-11 11:29 AM|只看該作者
若新密碼無法使用,可能是數據未更新。請使用舊密碼看看。
小弟想到解決的方法了,謝謝看過問題的各位。
如果發覺自己無法使用一些功能或出現問題,請按重新整理一次,並待所有網頁內容完全載入後5秒才進行操作。

使用道具檢舉

Rank: 1

帖子
49
積分
183 點
潛水值
19570 米
3
發表於 2012-11-11 02:08 PM|只看該作者
本帖最後由 m0neypig 於 2012-11-11 02:40 PM 編輯

Let's assume we have 4 nodes A, B, C and D,
where A is head(left most), D is tail (right most):

Node                 A        B         C       D
Link pointer     0^B    A^C    B^D   D^0
...
瀏覽完整內容,請先 註冊登入會員
成為伊莉的版主,你將獲得更高級和無限的權限。把你感興趣的版面一步步地發展和豐盛,那種滿足感等著你來嚐嚐喔。

使用道具檢舉

Rank: 1

帖子
49
積分
183 點
潛水值
19570 米
4
發表於 2012-11-11 02:26 PM|只看該作者
成為伊莉的版主,你將獲得更高級和無限的權限。把你感興趣的版面一步步地發展和豐盛,那種滿足感等著你來嚐嚐喔。
本帖最後由 m0neypig 於 2012-11-11 02:37 PM 編輯

Since I am so bored  (= =;)
and this problem is quite interesting, I attach my solution to this problem in C++.
The code is wrapped up in a hurry so please take it easy on me.
(and there are a lot of error handlings undone..)

  1. #include <string>
  2. #include <iostream>
  3. #include <sstream>

  4. // those macro are bad... but i'm lazy
  5. #define PRINT_CMD cout << "Choice [1]insert [2]show list [3]exit: "
  6. #define PRINT_ERR1 cout << "Unrecognized options, please enter 1, 2 or 3\n"
  7. #define PRINT_ERR2 cout << "Please insert the number first...\n"

  8. using namespace std;

  9. class Node
  10. {
  11. private:
  12.         int mLink;
  13.         int mVal;

  14. public:
  15.         Node(int val):mVal(val), mLink(0){}
  16.         ~Node(){};

  17.         // append the value to the right hand side of the list
  18.         // and return the right most node we just create
  19.         // precondition: we are in the most right hand side!
  20.         Node * append(int val)
  21.         {
  22.                 Node * node  = new Node(val);
  23.                 mLink = mLink ^ (int)node;
  24.                 node->mLink = (int)this ^ 0;
  25.                 return node;
  26.         }

  27.         static void iterate(Node * list)
  28.         {
  29.                 Node * pre = 0;
  30.                 Node * cur = list;

  31.                 while(cur->mLink != (int)pre){
  32.                         cout << cur->mVal << " " ;
  33.                         Node * temp = cur;
  34.                         cur = (Node *)( (int)pre ^ cur->mLink);
  35.                         pre = temp;
  36.                 }
  37.                 cout << cur->mVal << endl;
  38.         }

  39.         static void releaseResource(Node * list)
  40.         {
  41.                 if(list == NULL) return;
  42.                 Node * pre = 0;
  43.                 Node * cur = list;
  44.                 while(cur->mLink != (int)pre){
  45.                         Node * temp = cur;
  46.                         cur = (Node *)( (int)pre ^ cur->mLink);
  47.                         delete pre;
  48.                         pre = temp;
  49.                 }
  50.                 delete pre;
  51.                 delete cur;
  52.         }
  53. };//class Node

  54. int main()
  55. {
  56.     Node * leftMost = NULL;
  57.     Node * rightMost = NULL;

  58.     string line;
  59.     PRINT_CMD;
  60.    
  61.     while ( getline(std::cin, line))
  62.     {
  63.         if(line.compare("1")==0){
  64.             if( getline(std::cin, line) ){
  65.                 istringstream iss (line,istringstream::in);
  66.                 int val;
  67.                 bool firstTime = true;
  68.                 while(iss >> val){
  69.                     if(firstTime){
  70.                         leftMost = new Node(val);
  71.                         rightMost = leftMost;
  72.                         firstTime= false;
  73.                     }
  74.                     else
  75.                         rightMost = rightMost->append(val);
  76.                 }
  77.             }
  78.         }
  79.         else if(line.compare("2")==0){
  80.             if(leftMost==NULL){
  81.                 PRINT_ERR2;
  82.                 PRINT_CMD;
  83.                 continue;
  84.             }
  85.             cout << "Left to Right :";
  86.             Node::iterate(leftMost);
  87.             cout << "Right to Left:";
  88.             Node::iterate(rightMost);
  89.         }
  90.         else if(line.compare("3")==0) {
  91.             Node::releaseResource(leftMost);
  92.             break;
  93.         }
  94.         else{
  95.             PRINT_ERR1;
  96.         }
  97.         PRINT_CMD;
  98.     }
  99.     return 0;
  100. }
複製代碼


...
瀏覽完整內容,請先 註冊登入會員
若新密碼無法使用,可能是數據未更新。請使用舊密碼看看。

使用道具檢舉

ycess87009 該用戶已被刪除
5
發表於 2012-11-11 06:05 PM|只看該作者
如果瀏覽伊莉時速度太慢或無法連接,可以使用其他分流瀏覽伊莉,www01.eyny.com(02,03)。
本帖最後由 ycess87009 於 2012-11-11 06:10 PM 編輯

Thank you for your exposition. (^O^)





分享使你變得更實在,可以使其他人感到快樂,分享是我們的動力。今天就來分享你的資訊、圖片或檔案吧。

使用道具檢舉

您需要登錄後才可以回帖 登錄 | 註冊

Powered by Discuz!

© Comsenz Inc.

重要聲明:本討論區是以即時上載留言的方式運作,對所有留言的真實性、完整性及立場等,不負任何法律責任。而一切留言之言論只代表留言者個人意見,並非本網站之立場,用戶不應信賴內容,並應自行判斷內容之真實性。於有關情形下,用戶應尋求專業意見(如涉及醫療、法律或投資等問題)。 由於本討論區受到「即時上載留言」運作方式所規限,故不能完全監察所有留言,若讀者發現有留言出現問題,請聯絡我們。有權刪除任何留言及拒絕任何人士上載留言,同時亦有不刪除留言的權利。切勿上傳和撰寫 侵犯版權(未經授權)、粗言穢語、誹謗、渲染色情暴力或人身攻擊的言論,敬請自律。本網站保留一切法律權利。
回頂部