#include using namespace std;
#define pelinear_list_success 0//操作成功
#define pelinear_list_error_overflow 1//操作失敗:溢位
#define pelinear_list_error_notenough 2//操作失敗:記憶體不夠
#define pelinear_list_error_index 3//索引值不在範圍內
template class pelinelist
;template pelinelist::pelinelist( int len )
template pelinelist::~pelinelist()
template void pelinelist::printferror( int error )
//switch( error )
}template void pelinelist::printfelement( void )
//0 == length
else
//i} cout << endl;
}template int pelinelist::setelement( int index, t data )
//index >= 0 || index < length
else }
template int pelinelist::insert( int index, t data )
//( length + 1 ) > maxlen
else
//ielement[index] = data;
++length;//長度加一
return pelinear_list_success; }}
template int pelinelist::add( t data )
//0 == length
else if( length >= maxlen )//超出最大範圍
// else }
template int pelinelist::delete( int index )
//index < 0 || index >= length
if( index == ( length - 1 ) )//最後乙個元素,直接刪除
//index == ( length - 1 )
else//不是最後乙個元素,要進行移位操作
//i--length;
} return pelinear_list_success;
}void main()
程式執行結果: 資料結構 線性表的實現
1.順序表 pragma gcc optimize 2 include include include include include include include include include include include include include include include in...
資料結構線性表c
time limit 1000ms memory limit 65536k 輸入n個無序的整數,建立乙個有序鍊錶,鍊錶中的結點按照數值非降序排列,輸出該有序鍊錶。第一行輸入整數個數n 第二行輸入n個無序的整數。依次輸出有序鍊錶的結點值。6 33 6 22 9 44 5 5 6 9 22 33 44 ...
資料結構 線性表 陣列實現
按照上述抽象描述,定義乙個模板類來描述上述的抽象描述。templateclass linearlist bool isempty const 判斷線性表是否為空 int length const 線性表長度 bool find int k,t x const 返回第k個元素到x中 int searc...