锘??xml version="1.0" encoding="utf-8" standalone="yes"?>狠狠色丁香久久综合五月,99久久婷婷国产一区二区,99精品国产综合久久久久五月天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;
};



]]>
国内精品人妻无码久久久影院导航| 91精品国产乱码久久久久久| 人妻无码久久精品| 亚洲精品国产美女久久久| 一本伊大人香蕉久久网手机| 久久久亚洲AV波多野结衣| 久久综合欧美成人| 久久99国内精品自在现线| 久久综合九色综合久99| 久久久久人妻一区精品色| 久久久精品日本一区二区三区| 久久久无码人妻精品无码| 久久久久久亚洲精品无码| 91久久香蕉国产熟女线看| 看久久久久久a级毛片| 伊人久久成人成综合网222| 亚洲天堂久久精品| 99久久综合狠狠综合久久止| 精品多毛少妇人妻AV免费久久 | 久久综合狠狠综合久久综合88| 亚洲欧美精品伊人久久| 久久电影网一区| 亚洲AV无码成人网站久久精品大| 久久国产视频99电影| 国产激情久久久久影院老熟女免费 | 久久精品无码一区二区三区免费| 精品午夜久久福利大片| 国产精品一久久香蕉国产线看观看 | 亚洲日韩欧美一区久久久久我 | 欧美成人免费观看久久| 狠狠综合久久综合中文88| AAA级久久久精品无码区| 久久免费美女视频| 亚洲一本综合久久| 久久精品成人欧美大片| 亚洲午夜无码久久久久小说| 无码国内精品久久人妻麻豆按摩| 亚洲国产成人久久综合野外| 久久精品日日躁夜夜躁欧美| 一本一本久久A久久综合精品| 五月丁香综合激情六月久久|