锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久精品人妻中文系列,亚洲精品tv久久久久,国产亚洲成人久久http://m.shnenglu.com/QUIRE-0216/category/4972.htmlzh-cnTue, 20 May 2008 02:59:30 GMTTue, 20 May 2008 02:59:30 GMT60鍙岄摼琛ㄧ殑浠g爜瀹炵幇http://m.shnenglu.com/QUIRE-0216/archive/2007/08/24/30770.htmlQUIRE-0216QUIRE-0216Fri, 24 Aug 2007 09:06:00 GMThttp://m.shnenglu.com/QUIRE-0216/archive/2007/08/24/30770.htmlhttp://m.shnenglu.com/QUIRE-0216/comments/30770.htmlhttp://m.shnenglu.com/QUIRE-0216/archive/2007/08/24/30770.html#Feedback3http://m.shnenglu.com/QUIRE-0216/comments/commentRss/30770.htmlhttp://m.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浜嗕袱涓璞★紝鏄負(fù)浜咺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;
};



]]>
久久99国产一区二区三区| 久久精品一区二区三区AV| 久久久久国产一级毛片高清版| 久久99精品久久久久婷婷| 国产一区二区三区久久| 伊人久久大香线焦综合四虎 | 久久青青草原精品国产软件| 久久久久黑人强伦姧人妻| 欧美日韩精品久久久久| 久久精品国产99国产电影网 | 久久久久国产成人精品亚洲午夜| 色青青草原桃花久久综合| 潮喷大喷水系列无码久久精品| 久久久久婷婷| 国产一区二区精品久久| 热99RE久久精品这里都是精品免费| 国产精品久久久久久久久鸭 | 无夜精品久久久久久| 2020久久精品国产免费| 久久综合亚洲色一区二区三区| 国内精品伊人久久久久网站| 久久香综合精品久久伊人| 99久久夜色精品国产网站| 亚洲国产精品成人久久蜜臀| 日本精品久久久中文字幕| 久久国产高潮流白浆免费观看| 少妇久久久久久被弄到高潮 | 亚洲综合久久夜AV | 精品熟女少妇aⅴ免费久久| 精品久久久久久成人AV| 久久人妻少妇嫩草AV无码专区| 免费无码国产欧美久久18| 久久久久国色AV免费看图片| 久久精品国产一区二区三区 | 国产成人精品久久亚洲高清不卡| 亚洲AV日韩精品久久久久久久| 怡红院日本一道日本久久 | 亚洲精品WWW久久久久久| 久久久99精品一区二区| 久久国产视频99电影| 久久久人妻精品无码一区|