锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久精品人妻中文系列,亚洲精品tv久久久久,国产亚洲成人久久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浜嗕袱涓璞★紝鏄負(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;
};



]]>
久久成人影院精品777| 久久久久九国产精品| 亚洲欧美日韩中文久久| 亚洲综合伊人久久大杳蕉| 久久夜色精品国产噜噜麻豆| 国产成人久久AV免费| 久久夜色撩人精品国产| 色综合久久久久无码专区 | 99热都是精品久久久久久| 久久e热在这里只有国产中文精品99 | 久久男人Av资源网站无码软件| 99久久er这里只有精品18| 韩国三级中文字幕hd久久精品| 波多野结衣久久一区二区| 久久线看观看精品香蕉国产| 久久久国产视频| 久久国产精品免费一区| 婷婷久久香蕉五月综合加勒比 | 国产aⅴ激情无码久久| 久久久国产精品| 亚洲精品高清久久| 久久精品国产清高在天天线| 久久综合五月丁香久久激情| 久久综合久久综合九色| 久久久久女人精品毛片| 一本一本久久a久久综合精品蜜桃 一本一道久久综合狠狠老 | 亚洲综合伊人久久综合| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 久久噜噜电影你懂的| 99久久免费国产精精品| 色欲久久久天天天综合网精品 | 99久久精品影院老鸭窝| 久久综合久久自在自线精品自| 久久综合鬼色88久久精品综合自在自线噜噜 | 老男人久久青草av高清| 久久午夜无码鲁丝片秋霞| 亚洲国产成人精品无码久久久久久综合 | 99久久综合狠狠综合久久止| 亚洲中文久久精品无码ww16| 亚洲欧美日韩精品久久亚洲区| 久久久久人妻一区精品|