锘??xml version="1.0" encoding="utf-8" standalone="yes"?>97久久久久人妻精品专区,久久精品国产亚洲AV无码娇色,国产一区二区三区久久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浜嗕袱涓璞★紝鏄負浜咺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;
};



]]>
久久精品免费一区二区| 久久精品国产亚洲Aⅴ蜜臀色欲 | 国产V亚洲V天堂无码久久久| 伊人久久大香线蕉av不卡| 99久久久国产精品免费无卡顿 | 亚洲综合久久夜AV | 无码国内精品久久人妻蜜桃| 久久99国产精品一区二区| 亚洲国产精品综合久久一线| 国内精品久久久久伊人av| 久久久WWW成人| 国产成人久久精品激情| 亚洲第一永久AV网站久久精品男人的天堂AV| 久久无码AV中文出轨人妻| 久久综合九色综合97_久久久| 日批日出水久久亚洲精品tv| 久久99精品久久久久子伦| 综合久久给合久久狠狠狠97色| 精品久久久久久国产| 久久久久亚洲AV无码观看| 久久精品无码一区二区三区免费| 影音先锋女人AV鲁色资源网久久 | 99精品国产免费久久久久久下载| 97久久精品人人做人人爽| 99蜜桃臀久久久欧美精品网站 | 久久最新精品国产| 久久国产精品成人片免费| 人人妻久久人人澡人人爽人人精品| 久久中文娱乐网| 亚洲狠狠综合久久| 国产一级持黄大片99久久| 国产∨亚洲V天堂无码久久久| 国内精品伊人久久久久777| 一本久道久久综合狠狠躁AV| 99热成人精品免费久久| 91久久精品国产91性色也| 精品久久久久中文字幕日本| 久久亚洲私人国产精品| 国产精品一区二区久久不卡| 天堂久久天堂AV色综合| 久久这里只有精品18|