本文整理汇总了C++中ListInsert函数的典型用法代码示例。如果您正苦于以下问题:C++ ListInsert函数的具体用法?C++ ListInsert怎么用?C++ ListInsert使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ListInsert函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(void)
{
/// create list
SqList List;
InitList(&List);
/// insert element to list
ListInsert(&List, 1, 1);
ListInsert(&List, 2, 2);
ListInsert(&List, 3, 3);
ListInsert(&List, 4, 4);
ListInsert(&List, 5, 5);
/// locate element
printf("element %d is in %d\n", 4, LocateElem(&List, 4));
/// list length
int length = ListLength(&List);
printf("List length is %d\n", length);
/// get list element
int i, element;
for (i = 1; i <= length; i++) {
GetElem(&List, i, &element);
printf("element in %d is %d\n", i, element);
}
/// delect element from list
ListDelete(&List, 4, &element);
printf("deleted element in %d is %d\n", 4, element);
/// clear list
ClearList(&List);
printf("List empty is %d\n", ListEmpty(&List));
return EXIT_SUCCESS;
}
示例2: MergeList
void MergeList(SqList La,SqList Lb,SqList &Lc) // 算法2.2
{ // 已知线性表La和Lb中的数据元素按值非递减排列。
// 归并La和Lb得到新的线性表Lc,Lc的数据元素也按值非递减排列
int i=1,j=1,k=0;
int La_len,Lb_len;
ElemType ai,bj;
InitList(Lc); // 创建空表Lc
La_len=ListLength(La);
Lb_len=ListLength(Lb);
while(i<=La_len&&j<=Lb_len) // 表La和表Lb均非空
{
GetElem(La,i,ai);
GetElem(Lb,j,bj);
if(ai<=bj)
{
ListInsert(Lc,++k,ai);
++i;
}
else
{
ListInsert(Lc,++k,bj);
++j;
}
} // 以下两个while循环只会有一个被执行
while(i<=La_len) // 表La非空且表Lb空
{
GetElem(La,i++,ai);
ListInsert(Lc,++k,ai);
}
while(j<=Lb_len) // 表Lb非空且表La空
{
GetElem(Lb,j++,bj);
ListInsert(Lc,++k,bj);
}
}
示例3: main
int main()
{
DPoint _PFir;
DPoint _PSec;
DPoint _PAim;
DPoint _pCro;
_PFir._PointX=0.0;
_PFir._PointY=0.0;
_PSec._PointX=100.0;
_PSec._PointY=0.0;
_PAim._PointX=20.0;
_PAim._PointY=60.0;
CalcuVertical(_PFir,_PSec, _PAim,&_pCro);
printf("%.6lf, %.6lf", _pCro._PointX, _pCro._PointY);
printf("%.6lf",CalcuDis(_PFir,_PSec,_PAim));
////////////////////////////////////////
SqList lo;
ListInit(&lo);
DPoint _dPValue;
DPoint _dPIValue;
_dPValue._PointX = 100.0;
_dPValue._PointY = 100.0;
_dPIValue._PointX = 300.0;
_dPIValue._PointY = 300.0;
for (size_t _i=0;_i<3;_i++)
{
ListInsert(&lo,1,_dPValue);
}
ListInsert(&lo,2,_dPIValue);
printf("%.6lf,%.6lf",lo._nArray[0]._PointX,lo._nArray[0]._PointX);
//////////////////////////////////////
// vector<vector<CPoint>> _vecPOINT;
// vector<CPoint> _vecIn;
// CPoint _ptFir;
// CPoint _ptIn;
// _ptIn.SetPoint(300,300);
// _ptFir.SetPoint(100,100);
//
// _vecIn.push_back(_ptFir);
// for (size_t _i=0; _i<5;_i++)
// {
// _vecIn.push_back(_ptFir);
//_vecPOINT.push_back(_vecIn);
// }
//
// _vecPOINT.push_back(_vecIn);
//
// _vecPOINT[0].insert(_vecPOINT[0].begin()+1,_ptIn);
///////////////////////////////////////
return 0;
}
示例4: MergeList1
//Merge1
void MergeList1(SLinkList L)
{
int n=10;
int i=0;
ElemType e;
int j=0;
InitList(L);
printf("请输入A中数据的个数:");
scanf("%d",&i);
if(i>0)
n=i;
for(i=0;i<n;i++)
{
loop:
scanf("%d",&e);
if(!LocateElem(L,e,compare))
ListInsert(L,i+1,e);
else
{
printf("已存在,请重新输入:");
goto loop;
}
}
printf("遍历链表");
TraverseList(L,visit);
printf("\n");
printf("请输入B中数据的个数:");
scanf("%d",&i);
if(i>0)
n=i;
for(i=0;i<n;i++)
{
scanf("%d",&e);
if(!(j=LocateElem(L,e,compare)))
{
ListInsert(L,ListLength(L)+1,e);
}
else
{
ListDelete(L,j,e);
}
}
printf("遍历链表");
TraverseList(L,visit);
printf("\n");
}
示例5: main
int main(int argc, char *argv[])
{
char initial[10001] = {0};
int n, i;
char ch;
List L;
#ifdef _OJ_
const int SZ = 1<<20;
char inbuf[SZ];
char outbuf[SZ];
setvbuf(stdin,inbuf,_IOFBF,SZ);
setvbuf(stdout,outbuf,_IOFBF,SZ);
#endif
scanf("%s", initial);
InitList(&L, initial);
scanf("%d", &n);
while( n-- )
{
scanf("%d %c", &i, &ch);
ListInsert(L, i, ch);
ListTraverse(L);
}
return 0;
}
示例6: main
int main()
{
struct SqList L;
InitList(&L);
printf("ListEmpty(L) = %d\n", ListEmpty(L));
printSqList(L);
int e;
int index = 7;
GetElem(L, index, &e);
printf("the %d th number is e : %d\n", index, e);
printf("Find %d at index %d\n", e, Locate(L, e));
int insertNum = 100;
ListInsert(&L, index, 100);
printf("Insert %d at index %d into SqList\n", insertNum, index);
printSqList(L);
ListDelete(&L, index, &e);
printf("Delete %d at index %d from SqlList\n", e, index);
printSqList(L);
printf("ListLength(L) = %d\n", ListLength(L));
ClearList(&L);
printf("ListEmpty(L) = %d\n", ListEmpty(L));
printSqList(L);
return 0;
}
示例7: NewWatchedFile
static WatchedFile* NewWatchedFile(const WCHAR* filePath, const std::function<void()>& onFileChangedCb) {
bool isManualCheck = PathIsNetworkPath(filePath);
AutoFreeW dirPath(path::GetDir(filePath));
WatchedDir* wd = nullptr;
bool newDir = false;
if (!isManualCheck) {
wd = FindExistingWatchedDir(dirPath);
if (!wd) {
wd = NewWatchedDir(dirPath);
if (!wd)
return nullptr;
newDir = true;
}
}
WatchedFile* wf = AllocStruct<WatchedFile>();
wf->filePath = str::Dup(filePath);
wf->onFileChangedCb = onFileChangedCb;
wf->watchedDir = wd;
wf->isManualCheck = isManualCheck;
ListInsert(&g_watchedFiles, wf);
if (wf->isManualCheck) {
GetFileState(filePath, &wf->fileState);
AwakeWatcherThread();
} else {
if (newDir)
StartMonitoringDirForChanges(wf->watchedDir);
}
return wf;
}
示例8: MediaSrvRegistCallback
////////////////////////////////////////////////////
// 功能:
// 输入:
// 输出:
// 返回:
// 说明:
////////////////////////////////////////////////////
int MediaSrvRegistCallback(int type, DWORD device, PMEDIA_CALLBACK callback)
{
PLIST n;
PLIST head;
PCALLBACK_LINK check;
PCALLBACK_LINK link;
// 申请节点,并初始化
link = kmalloc(sizeof(CALLBACK_LINK));
if(link == NULL)
return -1;
kmemcpy(&link->Callback, callback, sizeof(MEDIA_CALLBACK));
link->Type = type;
link->Device = device;
ListInit(&link->Link);
// 检查设备是否已经注册
head = &MediaCallbackList;
for(n=ListFirst(head); n!=head; n=ListNext(n))
{
check = ListEntry(n, CALLBACK_LINK, Link);
if(&check->Callback == callback)
{
kfree(link);
return -1;
}
}
ListInsert(&MediaCallbackList, &link->Link);
return 0;
}
示例9: main
int main()
{
int i = 0;
char Sq_list[MAX] = "abcdefg";
char data;
printf("The content of the list\n");
for(i = 0;(i < MAX && Sq_list[i] != 0); i++)
{
printf("%c\t",Sq_list[i]);
if((i+1)%8 == 0)
printf("\n");
}
printf("\n");
unsigned int position = 0;
printf("Put in the position you wanner to insert!\n");
scanf("%d,",&position);
printf("Put in the data you wanner insert\n");
scanf("%c",&data);
ListInsert(Sq_list,position,data);
printf("The insert result:\n");
for(i = 0;(i < MAX && Sq_list[i] != 0); i++)
{
printf("%c\t",Sq_list[i]);
if((i+1)%8 == 0)
printf("\n");
}
}
示例10: PathIsNetworkPath
static WatchedFile *NewWatchedFile(const WCHAR *filePath, FileChangeObserver *observer)
{
bool isManualCheck = PathIsNetworkPath(filePath);
ScopedMem<WCHAR> dirPath(path::GetDir(filePath));
WatchedDir *wd = nullptr;
bool newDir = false;
if (!isManualCheck) {
wd = FindExistingWatchedDir(dirPath);
if (!wd) {
wd = NewWatchedDir(dirPath);
if (!wd)
return nullptr;
newDir = true;
}
}
WatchedFile *wf = AllocStruct<WatchedFile>();
wf->filePath = str::Dup(filePath);
wf->observer = observer;
wf->watchedDir = wd;
wf->isManualCheck = isManualCheck;
ListInsert(&g_watchedFiles, wf);
if (wf->isManualCheck) {
GetFileState(filePath, &wf->fileState);
AwakeWatcherThread();
} else {
if (newDir)
StartMonitoringDirForChanges(wf->watchedDir);
}
return wf;
}
示例11: RegisterLayoutCreatorFor
void RegisterLayoutCreatorFor(const char *layoutName, LayoutCreatorFunc creator)
{
LayoutCreatorNode *lc = AllocStruct<LayoutCreatorNode>();
lc->typeName = str::Dup(layoutName);
lc->creator = creator;
ListInsert(&gLayoutCreators, lc);
}
示例12: test_Increment
void test_Increment(void) {
LIST_TYPE list = NULL;
Status result = InitialList(&list);
int size = LIST_INITIAL_SIZE + LIST_INCREMENT;
CU_ASSERT_EQUAL(result, OK);
if (result != OK)
return;
int i = 0;
for (i = 0; i < size - 1; i++) {
result = ListInsert(list, 1, i);
CU_ASSERT_EQUAL(result, OK);
if (result != OK)
return;
}
CU_ASSERT_EQUAL(list -> listsize, size);
CU_ASSERT_EQUAL(list -> length, size - 1);
for (i = 0; i < size - 1; i++) {
CU_ASSERT_EQUAL(*(list -> element + i), size
- i - 2);
}
}
示例13: main
int main(void)
{
ElemType site[11] = { 'a', 'n', 'o', 't', 'h', 'e', 'r', 'h', 'o', 'm', 'e' };
LinkList *Link, *LinkR;
ElemType e;
CreateListF(Link, site, 11);
CreateListR(LinkR, site, 11);
DispList(Link);
DispList(LinkR);
DestroyList(LinkR);
if (ListEmpty(Link))
{
printf("List is empty\n");
}
else
{
printf("List isn't empty\n");
}
printf("ListLength: %d\n", ListLength(Link));
GetElem(Link, ListLength(Link), e);
ListInsert(Link, 2, e);
DispList(Link);
ListDelete(Link, 3, e);
DispList(Link);
printf("The location of 'o' is %d\n", LocateElem(Link, 'o'));
DestroyList(Link);
return 0;
}
示例14: main
void main()
{
SqList La,Lb,Lc;
int j,a[4]={3,5,8,11},b[7]={2,6,8,9,11,15,20};
InitList(La); // 创建空表La
for(j=1;j<=4;j++) // 在表La中插入4个元素
ListInsert(La,j,a[j-1]);
printf("La= "); // 输出表La的内容
ListTraverse(La,print1);
InitList(Lb); // 创建空表Lb
for(j=1;j<=7;j++) // 在表Lb中插入7个元素
ListInsert(Lb,j,b[j-1]);
printf("Lb= "); // 输出表Lb的内容
ListTraverse(Lb,print1);
MergeList(La,Lb,Lc);
printf("Lc= "); // 输出表Lc的内容
ListTraverse(Lc,print1);
}
示例15: ListInsert
void CLuaCallInHandler::AddHandle(CLuaHandle* lh)
{
ListInsert(handles, lh);
#define ADDHANDLE(name) \
if (lh->HasCallIn(#name)) { ListInsert(list ## name, lh); }
ADDHANDLE(GamePreload);
ADDHANDLE(GameStart);
ADDHANDLE(GameOver);
ADDHANDLE(TeamDied);
ADDHANDLE(UnitCreated);
ADDHANDLE(UnitFinished);
ADDHANDLE(UnitFromFactory);
ADDHANDLE(UnitDestroyed);
ADDHANDLE(UnitTaken);
ADDHANDLE(UnitGiven);
ADDHANDLE(UnitIdle);
ADDHANDLE(UnitCmdDone);
ADDHANDLE(UnitDamaged);
ADDHANDLE(UnitExperience);
ADDHANDLE(UnitSeismicPing);
ADDHANDLE(UnitEnteredRadar);
ADDHANDLE(UnitEnteredLos);
ADDHANDLE(UnitLeftRadar);
ADDHANDLE(UnitLeftLos);
ADDHANDLE(UnitLoaded);
ADDHANDLE(UnitUnloaded);
ADDHANDLE(UnitCloaked);
ADDHANDLE(UnitDecloaked);
ADDHANDLE(FeatureCreated);
ADDHANDLE(FeatureDestroyed);
ADDHANDLE(Explosion);
ADDHANDLE(StockpileChanged);
ADDHANDLE(Update);
ADDHANDLE(DefaultCommand);
ADDHANDLE(DrawGenesis);
ADDHANDLE(DrawWorld);
ADDHANDLE(DrawWorldPreUnit);
ADDHANDLE(DrawWorldShadow);
ADDHANDLE(DrawWorldReflection);
ADDHANDLE(DrawWorldRefraction);
ADDHANDLE(DrawScreenEffects);
ADDHANDLE(DrawScreen);
ADDHANDLE(DrawInMiniMap);
}