void test_DeleteFirst(void) { Status status = ERROR; GENERALIZED_LIST_TYPE element = NULL, list = getGeneralizedList("(1,2)"); if (list == NULL) return; list = NULL; status = DeleteFirst(&list, &element); CU_ASSERT_EQUAL(status, OK); assertEqual(list, "()"); assertEqual(element, "()"); list = getGeneralizedList("(1)"); status = DeleteFirst(&list, &element); CU_ASSERT_EQUAL(status, OK); assertEqual(list, "()"); assertEqual(element, "(1)"); list = getGeneralizedList("(1, 2)"); status = DeleteFirst(&list, &element); CU_ASSERT_EQUAL(status, OK); assertEqual(list, "(2)"); assertEqual(element, "(1)"); list = getGeneralizedList( "((11,12,13),(21,22,23,24,25),3,(4,(51,52,53,(501,502))))"); status = DeleteFirst(&list, &element); CU_ASSERT_EQUAL(status, OK); assertEqual(list, "((21,22,23,24,25),3,(4,(51,52,53,(501,502))))"); assertEqual(element, "(11,12,13)"); }
int CNEOMemQueue::GetAndDeleteFirst(CNEODynamicBuffer *pBuffer) { int nRet=GetFirst(pBuffer); if(nRet) DeleteFirst(); return nRet; }
int CNEOMemQueue::GetAndDeleteFirst(char *szBuffer,int nBufferSize) { int nRet=GetFirst(szBuffer,nBufferSize); if(nRet) DeleteFirst(); return nRet; }
void HashTable::Delete(char* recname, int *index, int* relocation) { //Hash Table에서 데이터 지우기 int HA; HA = Hash(recname); int link = HA; *index = 0; *relocation = 0; if (strcmp(this->table[HA].name, recname) == 0) { DeleteFirst(HA, relocation); //HA에 위치해 있을경우 } else { int persu; persu = link; while (link != -1 && strcmp(this->table[link].name, recname) != 0) { persu = link; link = this->table[link].link; } if (link == -1 || strcmp(this->table[link].name, recname) != 0) { //없는 데이터이다 *index = -1; *relocation = -1; return; } DeleteMid(link, persu, relocation); //HA에 없고 체인상에 데이터가 존재하는 경우 } this->length--; *index = link; }
//枚举遍历所有数据,提交回调函数处理,并删除数据 int CNEOPopBuffer::MoveAllData(_NEO_ENUM_DATA_CALLBACK pCallBack,void *pCallParam) { int nMovedTokenCount=0; bool bCallbackRet=true; //if(!pCallBack) // goto CNEOPopBuffer_MoveAllData_End; if(!ICanWork()) goto CNEOPopBuffer_MoveAllData_End; while(m_pHead->m_nTokenCount) { char *pFirstTokenBegin=NEO_POP_BUFFER_FIRST_TOKEN_BEGIN(m_pBuffer); SNEOPopBufferTokenHead *pFirstTokenHead=(SNEOPopBufferTokenHead*)pFirstTokenBegin;//强制转换 char *pFirstTokenData=NEO_POP_BUFFER_TOKEN_DATA_BEGIN(pFirstTokenBegin); if(pCallBack) { bCallbackRet=pCallBack(pFirstTokenData,pFirstTokenHead->m_nDataLen,pCallParam); if(!bCallbackRet) break; } DeleteFirst(); nMovedTokenCount++; } CNEOPopBuffer_MoveAllData_End: return nMovedTokenCount; }
void Doom(List *ItWorks) { while(ItWorks->head!=NULL) { DeleteFirst(&Works); ItWorks->length=0; } }
int CNEOPopBuffer::GetAndDeleteFirst(CNEOStaticBuffer *pBuffer) { if(!ICanWork()) return 0; int nRet=GetFirst(pBuffer); DeleteFirst(); return nRet; }
//从队列总弹出第一个元素 int CNEOPopBuffer::GetAndDeleteFirst(char *szBuffer,int nBufferSize) { if(!ICanWork()) return 0; int nRet=GetFirst(szBuffer,nBufferSize);//获得第一个元素 DeleteFirst(); return nRet; }
void main() { SqList L; ElemType d,e; Status i; int n; printf("按非降序建立n个元素的线性表L,请输入元素个数n: "); scanf("%d",&n); CreatAscend(L,n); printf("依次输出L的元素:"); ListTraverse(L,visit); InsertAscend(L,10); // 按非降序插入元素10 printf("按非降序插入元素10后,线性表L为:"); ListTraverse(L,visit); HeadInsert(L,12); // 在L的头部插入12 EndInsert(L,9); // 在L的尾部插入9 printf("在L的头部插入12,尾部插入9后,线性表L为:"); ListTraverse(L,visit); printf("请输入要删除的元素的值: "); cin>>e; i=DeleteElem(L,e); if(i) cout<<"成功删除"<<e<<'!'<<endl; else cout<<"不存在元素"<<e<<'!'<<endl; printf("线性表L为:"); ListTraverse(L,visit); printf("请输入要取代的元素的序号 元素的新值: "); cin>>n>>e; ReplaceElem(L,n,e); printf("线性表L为:"); ListTraverse(L,visit); DestroyList(L); printf("销毁L后,按非升序重新建立n个元素的线性表L,请输入元素个数n(>2):"); scanf("%d",&n); CreatDescend(L,n); printf("依次输出L的元素:"); ListTraverse(L,visit); InsertDescend(L,10); // 按非升序插入元素10 printf("按非升序插入元素10后,线性表L为:"); ListTraverse(L,visit); printf("请输入要删除的元素的值: "); cin>>e; i=DeleteElem(L,e); if(i) cout<<"成功删除"<<e<<'!'<<endl; else cout<<"不存在元素"<<e<<'!'<<endl; printf("线性表L为:"); ListTraverse(L,visit); DeleteFirst(L,e); DeleteTail(L,d); cout<<"删除表头元素"<<e<<"和表尾元素"<<d<<"后,线性表L为:"<<endl; ListTraverse(L,visit); }
void main() { SqList L; ElemType d,e; Status i; int n; printf("按非降序建立n个元素的线性表L,请输入元素个数n: "); scanf("%d",&n); CreatAscend(&L,n); printf("依次输出L的元素:"); ListTraverse(L,visit); InsertAscend(&L,10); /* 按非降序插入元素10 */ printf("按非降序插入元素10后,线性表L为:"); ListTraverse(L,visit); HeadInsert(&L,12); /* 在L的头部插入12 */ EndInsert(&L,9); /* 在L的尾部插入9 */ printf("在L的头部插入12,尾部插入9后,线性表L为:"); ListTraverse(L,visit); printf("请输入要删除的元素的值: "); scanf("%d",&e); i=DeleteElem(&L,e); if(i) printf("成功删除%d\n",e); else printf("不存在元素%d!\n",e); printf("线性表L为:"); ListTraverse(L,visit); printf("请输入要取代的元素的序号 元素的新值: "); scanf("%d%d",&n,&e); ReplaceElem(L,n,e); printf("线性表L为:"); ListTraverse(L,visit); DestroyList(&L); printf("销毁L后,按非升序重新建立n个元素的线性表L,请输入元素个数n(>2): "); scanf("%d",&n); CreatDescend(&L,n); printf("依次输出L的元素:"); ListTraverse(L,visit); InsertDescend(&L,10); /* 按非升序插入元素10 */ printf("按非升序插入元素10后,线性表L为:"); ListTraverse(L,visit); printf("请输入要删除的元素的值: "); scanf("%d",&e); i=DeleteElem(&L,e); if(i) printf("成功删除%d\n",e); else printf("不存在元素%d!\n",e); printf("线性表L为:"); ListTraverse(L,visit); DeleteFirst(&L,&e); DeleteTail(&L,&d); printf("删除表头元素%d和表尾元素%d后,线性表L为:\n",e,d); ListTraverse(L,visit); }
int test_DeleteFirst() { solved=TRUE; DeleteFirst(&TEMPLIST); if (!solved) { printf("Operace DeleteFirst() nebyla implementována!\n"); return(FALSE); } print_elements_of_list(TEMPLIST); return(TRUE); }
// Overloaded assignment operator LList& LList::operator = (const LList & other) { // Check for auto-assignment if (this == &other) { return * this; } while (first != NULL) { DeleteFirst(); } for (LNode * n = other.first; n != NULL; n = n->next) { InsertLast (n->data); } return * this; }
int main() { FILE *p; p=fopen("input.dat","r"); o=fopen("output.dat","w"); char a[100],*c,*d; while(fgets(a,100,p)) { c=strtok(a," \n"); d=strtok(NULL," \n"); if(strcmp(c,"AF") == 0) { AddFirst(atoi(d), &Works); } else if (strcmp(c,"AL") == 0) { AddLast(atoi(d), &Works); } else if(strcmp(c,"DF")==0) { DeleteFirst(&Works); } else if(strcmp(c,"DL")==0) { DeleteLast(&Works); } else if(strcmp(c,"DE")==0) { DeleteElement(atoi(d), &Works); } else if(strcmp(c,"PRINT_ALL")==0) { print(&Works); } else if(strcmp(c,"PRINT_F")==0) { PrintNrOfElements(atoi(d), &Works); } else if(strcmp(c,"PRINT_L")==0) { PrintNrOfElementsLast(atoi(d), &Works); } else if(strcmp(c,"DOOM_THE_LIST")==0) { Doom(&Works); } } return 0; }
int main() { FILE *f1=fopen("input.dat","r"); FILE *f2=fopen("output.dat","w"); char s[15]; int data; p->head=0; p->tail=0; while(fscanf(f1, "%s", s)==1) { if(strcmp(s, "AF")==0) { fscanf(f1, " %d", &data); AddFirst(data); } if(strcmp(s, "AL")==0) { fscanf(f1, " %d", &data); AddLast(data); } if(strcmp(s, "DF")==0) DeleteFirst(); if(strcmp(s, "DL")==0) DeleteLast(); if(strcmp(s, "DE")==0) { fscanf(f1, "%d", &data); DeleteElem(data); } if(strcmp(s, "DOOM_THE_LIST")==0) Doom_The_List(); if(strcmp(s, "PRINT_ALL")==0) PrintAll(f2); if(strcmp(s, "PRINT_F")==0) { fscanf(f1, "%d", &data); PrintFirst(data, f2); } if (strcmp(s,"PRINT_L")==0) { fscanf(f1, "%d", &data); PrintLast(p->tail, data, f2); fprintf(f2, "\n"); } } return 0; }
// Delete the element at the end of the list bool LList::DeleteLast () { if(size==0)return false; if(size==1)return DeleteFirst();// if there is only one element, no need to find the //last position.. all you have to do is call "DeleteFirst"/ LNode *tmp = first; while(tmp->next->next!=NULL){// must find the 2nd to last element...tmp->next->next tmp =tmp->next; // this is the 2nd to last postion } delete tmp->next;// this is the next postion... which is the last node. tmp->next = NULL;// this is the new last node... which should be pointing at null. size--; return true; }
void DeleteLast(List *ItWorks) { struct Node *temp; temp=ItWorks->head; if(ItWorks->head==NULL) return; if(temp->next==NULL) { DeleteFirst(&Works); } else { while(temp->next->next!=NULL) { temp=temp->next; } free(temp->next); temp->next=NULL; } ItWorks->length--; }
int CNEOMemQueue::PopFromFirst4NEOPopBuffer(CNEOPopBuffer *pPopBuffer) { int nRet=0; if(!ICanWork()) goto CNEOMemQueue_PopFromFirst4NEOPopBuffer_End; if(!m_pHead) goto CNEOMemQueue_PopFromFirst4NEOPopBuffer_End; if(!m_pHead->m_pBuffer) { m_pDebug->DebugToFile("%s::PopFromFirst4NEOPopBuffer():Mm_pHead->m_pBuffer=NULL!\n",m_szAppName); goto CNEOMemQueue_PopFromFirst4NEOPopBuffer_End; } if(!m_pHead->m_nDataLen) { m_pDebug->DebugToFile("%s::PopFromFirst4NEOPopBuffer():Mm_pHead->m_nDataLen=NULL!\n",m_szAppName); goto CNEOMemQueue_PopFromFirst4NEOPopBuffer_End; } if(!pPopBuffer) { m_pDebug->DebugToFile("%s::PopFromFirst4NEOPopBuffer():pPopBuffer=NULL\n",m_szAppName); goto CNEOMemQueue_PopFromFirst4NEOPopBuffer_End; } nRet=pPopBuffer->AddLast(m_pHead->m_pBuffer,m_pHead->m_nDataLen); if(m_pHead->m_nDataLen!=nRet) { //这是buffer 装满了 goto CNEOMemQueue_PopFromFirst4NEOPopBuffer_End; } if(!DeleteFirst()) { m_pDebug->DebugToFile("%s::PopFromFirst4NEOPopBuffer():DeleteFirst fail\n",m_szAppName); goto CNEOMemQueue_PopFromFirst4NEOPopBuffer_End; } if(m_pHead)//递归,继续弹出 nRet+=PopFromFirst4NEOPopBuffer(pPopBuffer); CNEOMemQueue_PopFromFirst4NEOPopBuffer_End: return nRet; }
void DeleteElem(int x){ node *aux; if(p->head==0 || p->head->data==x) DeleteFirst(); else if(p->tail->data==x) DeleteLast(); else { aux=p->head; while(aux!=NULL && aux->data!=x) aux=aux->next; if(aux!=0) { aux->prev->next=aux->next; aux->next->prev=aux->prev; free(aux); } } }
void DeleteElement(int x,List *ItWorks) { while(ItWorks->head!=NULL && ItWorks->head->data==x) { DeleteFirst(&Works); } struct Node *temp,*temp2,*temp3; temp=ItWorks->head; while(temp->next!=NULL) { if(temp->next->data==x) { temp2=temp->next->next; temp3=temp->next; free(temp->next); temp->next=temp2; temp->prev=temp3; ItWorks->length--; } temp=temp->next; if(temp==NULL) break; } }
void List :: DeleteList(){ while( head != NULL) DeleteFirst(); }
void HashTable::DeleteMid(int s, int p, int* relocation) { int index = s; int link; int persu; int before = p; int indexArray[Tbl_Size]; int i = 0; bool check = false; indexArray[i] = s; i++; link = this->table[s].link; while (link != -1) { if (Hash(this->table[link].name) == s) { //HA가 S인 레코드를 찾는다 index = link; persu = before; check = true; } indexArray[i] = link; //link를 같이 저장 i++; before = link; link = this->table[link].link; } if (check == false) { //HA가 s를 못찾았으면 this->table[p].link = this->table[s].link; //부모의 링크 체인 값 수정 this->table[s] = type_record(); //더미 레코드 삽입 } else { int HA; int j, k; bool chk1; bool chk2; for (j = i - 1, chk1 = true; j > 0 && chk1; j--) { //체인에서 S이하 부분들의 위치인 indexArray[1~(i-1)]까지 탐색한다. HA = Hash(this->table[indexArray[j]].name); for (k = 0, chk2 = true; k < i && chk2; k++) { if (HA == indexArray[k]) { //사용한다면 chk2 = false; } } if (!chk2){ chk1 = false; } } if (j>=-1) { index = indexArray[j + 1]; persu = indexArray[j]; strcpy(this->table[s].name, this->table[index].name); this->table[s].age = this->table[index].age; (*relocation)++; DeleteMid(index, persu, relocation); //index값 지우기 } else { this->table[p].link = -1; //링크 끊기 DeleteFirst(s, relocation); //s값을 지우고 s부터 시작하는 체인 만들기 } } }
void CNEOMemQueue::CleanAll(void) //清除所有token { if(!ICanWork()) return; while(DeleteFirst()){} //循环删除第一个对象知道队列为空 }
// Destructor for the LList class // Delete from the beginning of the list until the list is empty LList::~LList () { while (first != NULL) { DeleteFirst(); } }
void DestroySingleLinkedList(List * l) { while(!ListEmpty(l)) DeleteFirst(l); }