freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內容

線性數(shù)學試題解答-在線瀏覽

2024-11-05 15:59本頁面
  

【正文】 。 //返回原隊頭元素值 } 讀取隊頭元素值函數(shù) templateclass Type Type QueueType :: GetFront ( ) { assert ( ! IsEmpty ( ) )。 //返回隊頭元素值 }410 假設以數(shù)組Q[m]存放循環(huán)隊列中的元素, 同時設置一個標志tag,以tag == 0和tag == 1來區(qū)別在隊頭指針(front)和隊尾指針(rear)相等時,隊列狀態(tài)為“空”還是“滿”?!窘獯稹垦h(huán)隊列類定義 include template class Type class Queue { //循環(huán)隊列的類定義 public: Queue ( int=10 )。 } void EnQueue ( Type amp。 Type DeQueue ( )。 void MakeEmpty ( ) { front = rear = tag = 0。amp。 } //判隊列空否 int IsFull ( ) const { return front == rear amp。 tag == 1。 //隊尾指針、隊頭指針和隊滿標志 Type *Q。 //隊列最大可容納元素個數(shù) } 構造函數(shù) template class TypeQueueType:: Queue ( int sz ) : rear (0), front (0), tag(0), m (sz) { //建立一個最大具有m個元素的空隊列。 //創(chuàng)建隊列空間 assert ( Q != 0 )。item ) { assert ( ! IsFull ( ) )。 //隊尾位置進1, 隊尾指針指示實際隊尾位置 Q[rear] = item。 //標志改1,表示隊列不空 } 刪除函數(shù) templateclass Type Type QueueType :: DeQueue ( ) { assert ( ! IsEmpty ( ) )。 //隊頭位置進1, 隊頭指針指示實際隊頭的前一位置tag = 0。 //返回原隊頭元素的值 } 讀取隊頭元素函數(shù) templateclass Type Type QueueType :: GetFront ( ) { assert ( ! IsEmpty ( ) )。 //返回隊頭元素的值 }411 若使用循環(huán)鏈表來表示隊列,p是鏈表中的一個指針?!窘獯稹?鏈式隊列的類定義 template class Type class Queue。 private: Type data。 //鏈域 public: QueueNode ( Type d = 0, QueueNode *l = NULL ) : data (d), link (l) { } //構造函數(shù) }。 //析構函數(shù) void EnQueue ( const Type amp。 //將item加入到隊列中 Type DeQueue ( )。 //查看隊頭元素的值 void MakeEmpty ( )。 } //判隊列空否 private: QueueNodeType *p。 隊列的析構函數(shù) template class Type QueueType::~Queue ( ) { //隊列的析構函數(shù) QueueNodeType *s。 p = plink。 } //逐個刪除隊列中的結點 } 隊列的插入函數(shù) template class Type void QueueType::EnQueue ( const Type amp。 plink = p。slink = plink。 //結點p指向新的隊尾 } } 隊列的刪除函數(shù) template class Type Type QueueType::DeQueue ( ) { if ( p == NULL ) { cout 隊列空, 不能刪除! endl。 } QueueNodeType *s = p。 //重新鏈接, 將結點s從鏈中摘下 Type retvalue = sdata。 //保存原隊頭結點中的值, 釋放原隊頭結點 return retvalue。 412 若將一個雙端隊列順序表示在一維數(shù)組V[m]中,兩個端點設為end1和end2,并組織成一個循環(huán)隊列。end2【解答】 初始化條件 end1 = end2 = 0。 隊滿條件 ( end1 + 1 ) % m = end2。 ~DoubleQueue ( ) { delete [ ] V。 item, const int end )。 Type GetFront (const int end )。 } //置空隊列 int IsEmpty ( ) const { return end1 == end2。 } //判兩隊列滿否 private: int end1, end2。 //存放隊列元素的數(shù)組 int m。 V = new Type[m]。 //斷言: 動態(tài)存儲分配成功與否 } 插入函數(shù) templateclass Type void DoubleQueueType :: EnQueue ( Type amp。 if ( end == 1 ) { end1 = ( end1 + 1 ) % m。 //end1指向實際隊頭位置 } else { V[end2] = item。 //end2指向實際隊頭的下一位置 } } 刪除函數(shù) templateclass Type Type DoubleQueueType :: DeQueue ( const int end ) { assert ( !IsEmpty ( ) )。 temp。 //先保存原隊頭元素的值, end1端指針退1end1 = ( end1 + m 1 ) % m。 temp = V[end2]。再保存原隊頭元素的值 } return temp。 Typeamp。if ( end == 1 ) return V[end1]。 }413 設用鏈表表示一個雙端隊列,要求可在表的兩端插入,但限制只能在表的一端刪除。【解答】 鏈式雙端隊列的類定義 template class Type class DoubleQueue。 private: Type data。 //鏈域public: DoubleQueueNode (Type d = 0, DoubleQueueNode *l = NULL) : data (d), link (l) { } //構造函數(shù) }。 //構造函數(shù) ~DoubleQueue ( )。 item )。 item )。 //刪除并返回隊頭end1元素 Type GetFront ( )。 //置空隊列 int IsEmpty ( ) const { return end1 == end1link。 //end1在鏈頭, 可插可刪。 隊列的構造函數(shù) templateclass Type doubleQueueType :: doubleQueue ( ) { //構造函數(shù) end1 = end2 = new DoubleQueueNodeType( )。end1link = end1。 //逐個刪除隊列中的結點, 包括表頭結點 while ( end1 != NULL ) { p = end1。 delete p。 item ) { if ( end1 == end1link ) //隊列空, 新結點成為第一個結點end2 = end1link = new DoubleQueueNodeType ( item, end1 )。 }template class Type //從隊列end2端插入void DoubleQueueType :: EnDoubleQueue2 ( const Typeamp。 } 隊列的刪除函數(shù)template class Type Type DoubleQueueType :: DeDoubleQueue ( ) { if ( IsEmpty ( )
點擊復制文檔內容
環(huán)評公示相關推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1