posts - 2,  comments - 0,  trackbacks - 0
          相關定義:

          struct LNode{
               int e;
               LNode* next;
          };
           

          typedef struct LNode* LinkList;

          非遞歸方法:

          //l 是帶頭結點的單鏈表
          void
           ReverseList(LinkList l){
               if(l==NULL || l->next == NULL)
                   return;
               LNode *p, *q, *r;
               p = l->next;
               q = p->next;
               while( q != NULL){
                   r = q->next;
                   q->next = p;
                   p = q;
                   q = r;
               }
           

               l->next->next = NULL;
               l->next = p;
          }

          遞歸方法:

          LNode* ReverseList_Recursive(LNode* pNode,LinkList& l){
           

               if ( (pNode == NULL|| (pNode->next == NULL) ){
                   l->next->next = NULL;
                   l->next = pNode; 
                   return pNode;
               }

               LNode* temp = ReverseList_Recursive(pNode->next, l);
               temp->next = pNode;
               return pNode;
          }


          posted on 2009-06-03 22:47 iConnect 閱讀(615) 評論(0)  編輯  收藏 所屬分類: 數學&算法&數據結構
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(2)

          文章分類(17)

          文章檔案(16)

          收藏夾(17)

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 同德县| 红原县| 昭苏县| 招远市| 巢湖市| 大余县| 卫辉市| 庆安县| 合水县| 鄱阳县| 洱源县| 灵丘县| 漳平市| 固始县| 洪泽县| 临湘市| 钦州市| 越西县| 阿合奇县| 芜湖县| 淮北市| 浑源县| 德钦县| 镇巴县| 丹寨县| 龙江县| 正蓝旗| 扎囊县| 岳阳市| 全椒县| 临沧市| 辽阳市| 英吉沙县| 大埔县| 桃园县| 唐河县| 类乌齐县| 远安县| 永昌县| 辽宁省| 汶上县|