刪除vector中的重複資料 unique

2022-01-14 20:43:26 字數 638 閱讀 3512

[cpp]view plain

copy

#include 

#include 

#include 

#include 

using namespace std;  

template  

inline void deduplication(t& c)   

int main()  

;  vector vec(ary, ary + sizeof(ary) / sizeof(int));  

//  

deduplication(vec);  

//  

copy(vec.begin(), vec.end(), ostream_iterator(cout, " "));  

system("pause");  

return 0;  

}  注:unique函式功能是去除相鄰的重複元素,注意是相鄰,所以必須先使用sort函式。還有乙個容易忽視的特性是它並不真正把重複的元素刪除。之所以說比不真正把重複的元素刪除,因為unique實際上並沒有刪除任何元素,而是將無重複的元素複製到序列的前段,從而覆蓋相鄰的重複元素。unique返回的迭代器指向超出無重複的元素範圍末端的下乙個位置。

刪除表中重複資料

刪除表中重複資料 取出line fancy2表中fancy name相同的最小fancy id 寫進tmp表 create table tmp as select min fancy id as col1 from line fancy2 group by fancy name 刪除line fan...

刪除表中重複資料

如果重複資料很多,被刪掉的可能是大部分記錄,業務又允許的情況下,可以考慮重建表 create table newtable as select distinct from table rename table to oldtable rename newtable to table create i...

excel中刪除重複資料

今天碰到的乙個問題,刪除重複資料,這裡做個記錄。一列資料,有很多重複專案,現在需要刪除重複的,如下圖所示 簡單的方法是,選中該列,工具欄 資料 專案中選擇 刪除重複項 按下確定 按下確定完成重複專案的清理 那麼從vba的角度如何刪除資料 測試用新增資料如下 sub adddata dim i as ...