C 實現順序表基本函式以及增刪查改

2021-08-04 11:20:36 字數 1159 閱讀 1254

下面的**是我們用c++實現的順序表,其中頭插頭刪,尾插尾刪函式可以復用insert函式,和erase函式。

#include

#include

#include

using namespace std;

typedef int datatype;

class

seqlist

seqlist

(const

seqlist& s)

//傳統寫法

seqlist& operator=(const

seqlist &s)

return *this;

}//現**法

//s1=s2

seqlist& operator=(seqlist

s)//不能加引用,會改變s2

~seqlist

()

}void swap

(seqlist& s)

void pushback

(datatype

x)

void popback

()

void pushfront

(datatype

x)

_array[0] = x;

++_size;

}void popfront

()

--_size;

}void insert

(size_t

pos, datatype

x)

else

_array[pos] = x;

}_size++;

}void erase

(size_t

pos)

_size--;

}datatype& operator(size_t

pos)

void checkcapacity

()

}void print

()

cout << endl;

}private:

datatype* _array;

size_t _size;

size_t _capacity;

};

C語言實現順序表的增刪查改以及排序

seqlist.h ifndef seqlist define seqlist define max 5 include typedef int datatype typedef struct seqlist seqlist void printseqlist seqlist pseq void i...

實現順序表的增刪查改

線性表分為兩種 順序表 順序儲存 和鍊錶 鏈式儲存 這裡實現一下順序表管理資料的增刪查改操作 標頭檔案自定義標頭檔案中一般存放自定義函式的函式宣告 sqlist.h pragma once include include include typedef int sqldatatype typedef...

順序表的增 刪 查 改實現(c語言)

資料結構順序表 實現增 刪 查 改四個功能 具體 如下 include include pragma warning disable 4996 define num 10 typedef int datetype typedef struct seqlist seqlist void test se...