单链表的相关问题

     # include   using  namespace 性传播疾病;   # include   template   struct 节点   {   int  _data;   节点*,_next;   节点(const  T&, x)   :_data (x)   ,_next(空)   {}   };      template   class  PlinkList   {   公众:   PlinkList ()   :_head(空)   {}   void 阻力(const  T&, x)   {   if  (_head ==, NULL)   {   时间=_head  new  Node< T> (x);   时间=_tail  _head;   }   其他的   {   Node *, tmp =, new  Node (x);   Node *, cur =, _head;   while  (cur→_next)   {   时间=cur  cur→_next;   }   tmp→_next =,坏蛋→_next;   坏蛋→_next =, tmp;   _tail =, tmp;   }   }   Node *, JosephusCycle (int  k)//约瑟夫环问题   {   断言(_head);   时间=_tail→_next  _head;   Node *, begin =, _head;   while  (1)   {   if (开始→_next ==,开始)   打破;   int  count =, k 作用;1;   while (计数——,祝辞,0)   {=//del 开始;   时间=begin 开始→_next;   }   Node *, del =,开始→_next;//交换(开始→_data,,开始→_next→_data);   开始→_next =,德尔→_next;   时间=begin 开始→_next;   delete 德尔;   }   return 开始;   }   void  Find_comm (Node *,,, Node *,两个)//找两个已排好序链表的相同数   {   断言(one ,,,两个);   Node *, cur1 =,;   Node *, cur2 =,两个;   while  (cur1 ,,, cur2)   {   if  (cur1→_data 祝辞,cur2→_data)   时间=cur2  cur2→_next;   else  if  (cur1→_data  & lt;, cur2→_data)   时间=cur1  cur1→_next;   其他的   {   cout  & lt; & lt;, cur1→_data  & lt; & lt;,“,”;   时间=cur1  cur1→_next;   时间=cur2  cur2→_next;   }   }   cout  & lt; & lt;,“not  comm 数据”,& lt; & lt;, endl;   }   Node *, Find_CenterNode(),//查找链表的中间节点   {   断言(_head);   Node *, slow =, _head;   Node *, fast =, _head;   while  (fast ,,,快→_next)   {   时间=slow 慢→_next;   时间=fast 快速→_next→_next;   }   return 慢;   }   bool  del_thelast_Knode (int  pos)//删除倒数第pos个节点   {   int  count =, 0;   Node *, cur =, _head;   while (坏蛋)   {   时间=cur  cur→_next;   数+ +;   }   if  (pos<0, | |, pos>计数)   return 假;   if  (pos ==,数)//如果要删除的为头结点   {   Node *, del =, _head;   时间=_head  _head→_next;   delete 德尔;   return 真实;   }/* else //采用快慢指针让快指针先走pos步,慢指针再走   {   Node *, slow =, _head;   Node *, fast =, _head;   Node *, prev =, _head;   int  k =, 0;   while (快)   {   if  (k 祝辞=,pos)   {   prev =,缓慢;   时间=slow 慢→_next;   }   时间=fast 快速→_next;   k + +;   }   Node *, del =,缓慢;   prev→_next =,德尔→_next;   delete 德尔;   return 真实;   } */else ,//也可走count-pos步并记录该位置的前一个位置   {   时间=count  count 作用;pos ;   int  num =, 0;   Node *, prev =, _head;   Node *, tmp =,上一页;   时间=cur  _head;   while  (cur→_next)   {   if  (num  +, 1,==,计数)   {   tmp =,坏蛋;   时间=cur  cur→_next;   打破;   }   时间=cur  cur→_next;//prev =,上一页→_next;   num + +;   }   Node *, del =,坏蛋;   tmp→_next =,德尔→_next;   delete 德尔;   return 真实;   }   }      Node *,反向()//逆置单链表   {   断言(_head);   if  (_head→_next ==, NULL)   return  _head;   Node *, cur =, _head;   Node *, newHead =,空;   while (坏蛋)   {   Node *, tmp =,坏蛋;   时间=cur  cur→_next;   tmp→_next =, newHead;   newHead =, tmp;   }   return  newHead;   }   void  PrintTailTohead (Node

单链表的相关问题