锘??xml version="1.0" encoding="utf-8" standalone="yes"?>97久久久久人妻精品专区,久久精品国产亚洲AV无码娇色,国产一区二区三区久久http://www.shnenglu.com/QUIRE-0216/category/4972.htmlzh-cnTue, 20 May 2008 02:59:30 GMTTue, 20 May 2008 02:59:30 GMT60鍙岄摼琛ㄧ殑浠g爜瀹炵幇http://www.shnenglu.com/QUIRE-0216/archive/2007/08/24/30770.htmlQUIRE-0216QUIRE-0216Fri, 24 Aug 2007 09:06:00 GMThttp://www.shnenglu.com/QUIRE-0216/archive/2007/08/24/30770.htmlhttp://www.shnenglu.com/QUIRE-0216/comments/30770.htmlhttp://www.shnenglu.com/QUIRE-0216/archive/2007/08/24/30770.html#Feedback3http://www.shnenglu.com/QUIRE-0216/comments/commentRss/30770.htmlhttp://www.shnenglu.com/QUIRE-0216/services/trackbacks/30770.html#ifndef _DOUBLE_H_
#define _DOUBLE_H_

template<class T>
class Double;

template<class T>
class DoubleNode
{
 friend class Double<T>;
private:
 T data;
 DoubleNode<T> *pre;
 DoubleNode<T> *next;
};

template<class T>
class Double
{
 public:
  Double();//{head=end=NULL;}
  ~Double();
  void Erase();
  void reverse();
  int GetLength()const;
  bool IsEmpty()const;
  bool Find(int k, T& x)const;
  int Search(T& x)const;
  Double<T>& Delete(int k, T& x);
  Double<T>& Insert(int k, const T& x);
  void output(ostream& out)const;
  friend ostream& operator << (ostream& out, const Double<T>& x);
 private:
  DoubleNode<T> *head;
  DoubleNode<T> *end;
  int length;
};

template<class T>
Double<T>::Double()
{
 head = new DoubleNode<T>;
 end = new DoubleNode<T>;
 head->pre = NULL;
 head->next = end;
 end->pre = head;
 end->next = NULL;

 length = 0;
}

template<class T>
Double<T>::~Double()
{
 Erase();
}

template<class T>
void Double<T>::Erase()
{
 DoubleNode<T> *current = head;
 while (current)
 {
  head = head->next;
  delete current;
  current = head;
 }
 length = 0;
}

template<class T>
int Double<T>::GetLength()const
{
 return length;
}

template<class T>
bool Double<T>::IsEmpty()const
{
 return length == 0;
}

template<class T>
bool Double<T>::Find(int k, T& x)const
{

 if (length == 0)
 {
  throw exception("DoubleNode is empty!");
 }
 else if(k<1 || k>length)
 {
  throw exception("no find the position of k");
 }

 DoubleNode<T> *current = head->next;
 for (int i=1; (i<k)&&current; ++i)
 {
  current = current->next;
 }

 if (current)
 {
  x = current->data;
  return true;
 }

 return false;
}


template<class T>
int Double<T>::Search(T& x)const
{
 int nIndex = 1;
 DoubleNode<T> *current = head->next;
 while (current && current->data != x)
 {
  ++nIndex;
  current = current->next;
 }

 if (current)
 {
  return nIndex;
 }

 return -1;
}

template<class T>
Double<T>& Double<T>::Delete(int k, T& x)
{
 if (length == 0)
 {
  throw exception("DoubleNode is empty!");
 }
 else if(k<1 || k>length)
 {
  throw exception("no find the position of k, so can't delete!");
 }

 DoubleNode<T> *current = head->next; 
 for (int i=1; (i<k)&&current; ++i)
 {
  current = current->next;
 }

 DoubleNode<T> * p = current;
 current->pre->next = current->next;
 current->next->pre = current->pre;

 x = p->data;
 delete p;
 p = NULL;
 --length;

 return *this;
}


template<class T>
Double<T>& Double<T>::Insert(int k, const T& x)
{
 if (k>=0 && k<= length)
 {
  DoubleNode<T> *newNode = new DoubleNode<T>;
  newNode->data = x;

  DoubleNode<T> *current = head;
  for (int i=0; i<k; ++i)
  {
   current = current->next;
  }

  newNode->pre = current;
  newNode->next = current->next;
  current->next->pre = newNode;
  current->next = newNode;
  
  
  ++length;
 }
 else
 {
  throw exception("no find the position of k, so can't insert!");
 }

 return *this;
}

template<class T>
void Double<T>::output(ostream& out)const
{
 DoubleNode<T> *current = head->next;
 while (current!=end)
 {
  out << current->data << " ";
  current = current->next;
 }
}

template<class T>
ostream& operator<< (ostream& out, const Double<T>& x)
{
 x.output(out);
 return out;
}

template<class T>
void Double<T>::reverse()
{
 DoubleNode<T> *p1 = head;
 DoubleNode<T> *p2 = NULL;
 DoubleNode<T> *pNode;

 while (p1 != NULL)
 {
  pNode = p1;
  pNode->pre = p1->next;
  p1 = p1->next;
  pNode->next = p2;
  p2 = pNode;
 }

 end = head;
 head = p2;
}

#endif

浠ヤ笂涓哄弻閾捐〃鐨勫熀鏈搷浣滐紝浠g爜宸茬粡嫻嬭瘯榪囦簡錛屽彲浠ョ洿鎺ョ敤錛?br>鍏朵腑錛宧ead. end鍦ㄦ瀯閫犲嚱鏁版椂錛孨ew浜嗕袱涓璞★紝鏄負浜咺nsert 鍜?Delete鎿嶄綔鐨勬柟渚匡紒
鏇村ソ鐨勬柟寮忔槸:鎶婃寚閽堝拰鏁版嵁鍒嗗紑錛岃繖鏍穐ead,end灝卞彲浠ヨ妭鐪佸瓨璐┖闂翠簡錛?br>鏂瑰紡濡備笅錛?br>//鎸囬拡鏁版嵁閮ㄥ垎錛堝悗緇寚閽堝拰鍓嶉┍鎸囬拡錛?br>struct Node_base
{
 Node_base *next;
 Node_base *pre;
};

//娣誨姞瀹為檯鏁版嵁閮ㄥ垎
template <class T>
struct Node : public Node_base
{
 T m_data;
};



]]>
欧美日韩中文字幕久久伊人| 色婷婷狠狠久久综合五月| 久久久久久国产精品无码超碰| 日产精品久久久久久久性色| 粉嫩小泬无遮挡久久久久久| 久久久久久国产精品免费免费| 久久久亚洲AV波多野结衣| 久久精品国产精品青草app| 亚洲а∨天堂久久精品9966| 国产精品对白刺激久久久| 久久夜色精品国产| 久久r热这里有精品视频| 久久久久高潮综合影院| 久久精品国产欧美日韩| 国内精品久久久久| 久久久久99精品成人片试看| 久久国内免费视频| 久久中文字幕无码专区| 国产成人精品久久综合| 99久久无码一区人妻a黑| 亚洲综合日韩久久成人AV| 久久久久久久91精品免费观看| 久久99精品久久久久久9蜜桃| 国产精品久久成人影院| 国内精品人妻无码久久久影院| 久久久久亚洲AV无码观看| 一本久久免费视频| 久久久久亚洲AV成人网人人软件| 香港aa三级久久三级| 久久精品国产免费| 久久香蕉一级毛片| 99久久国产综合精品五月天喷水| AV无码久久久久不卡蜜桃 | 久久99精品久久久久久hb无码| 久久久久久久综合狠狠综合| 久久综合伊人77777麻豆| 久久久久人妻一区精品| 四虎久久影院| 久久久久久精品无码人妻| 天天爽天天狠久久久综合麻豆| 狠狠色婷婷久久综合频道日韩 |