bool ServerClientList::removeClient( PlayerID client_id ) { ServerClientListData *client_data_ptr; if ( front == 0 ) return( false ); client_data_ptr = front; if ( client_data_ptr->client_id == client_id ) { deleteFront(); return( true ); } while( client_data_ptr->next != 0 ) { if ( client_data_ptr->next->client_id == client_id ) { deleteAfter( client_data_ptr ); return( true ); } client_data_ptr = client_data_ptr->next; } return( false ); }
void List::deleteElement(ListBox* pointer, int& x) { if (pointer == start) { x = pointer->info; if (start == end) { start = end = NULL; } else { start = start->pointer; delete pointer; } } else { ListBox* newElement = start; while (newElement->pointer != pointer) { newElement = newElement->pointer; } deleteAfter(newElement, x); } }
void main() { node *head,*tail; createList(&head); insertAtBeginning(&head,4); insertAtBeginning(&head,3); insertAtBeginning(&head,2); insertAtBeginning(&head,5); insertAtBeginning(&head,6); insertAtBeginning(&head,10); insertAtEnd(&head,1); insertInBetween(&head,9,2); traverseList(head); printf("\n"); reverseTraversal(head); reverseList(&head); traverseList(head); deleteEnd(&head); traverseList(head); deleteBeginning(&head); traverseList(head); deleteAfter(&head,2); traverseList(head); deleteList(&head); traverseList(head); // tail= getTail(head); // printf("\nTail= %d",tail->info); }
/* Delete completed edges. Update 'xIntersect' field for others */ void updateActiveList (int scan, Edge * active) { Edge * q = active, * p = active->next; while (p) if (scan >= p->yUpper) { p = p->next; deleteAfter (q); } else { p->xIntersect = p->xIntersect + p->dxPerScan; q = p; p = p->next; } }
int main() { int pil; infotype x, y; address P, Q; list L; createList(&L); while(pil != 10) { cout<<"1. Insert first"<<endl; cout<<"2. Insert after"<<endl; cout<<"3. Insert last"<<endl; cout<<"4. Delete first"<<endl; cout<<"5. Delete after"<<endl; cout<<"6. Delete last"<<endl; cout<<"7. View list"<<endl; cout<<"8. Search element"<<endl; cout<<"9. Search sentinel"<<endl; cout<<"Pilih: "; cin>>pil; switch(pil) { case 1: cout<<"ID : "; cin>>x.id; cout<<"Nama : "; cin>>x.nama; cout<<"Jabatan : "; cin>>x.jabatan; cout<<"Departemen : "; cin>>x.departemen; cout<<"Gaji : "; cin>>x.gaji; P = allocate(x); insertFirst(&L, P); cout<<endl; cout<<"Insert complete."; break; case 2: cout<<"ID : "; cin>>x.id; cout<<"Nama : "; cin>>x.nama; cout<<"Jabatan : "; cin>>x.jabatan; cout<<"Departemen : "; cin>>x.departemen; cout<<"Gaji : "; cin>>x.gaji; cout<<"Dimasukan setelah ID: "; cin>>y.id; if(searchElement(&L, y) != Nil) { insertAfter(&L, allocate(x), allocate(y)); cout<<endl; cout<<"Insert complete."; } else { cout<<"Data tidak ada."; } break; case 3: cout<<"ID : "; cin>>x.id; cout<<"Nama : "; cin>>x.nama; cout<<"Jabatan : "; cin>>x.jabatan; cout<<"Departemen : "; cin>>x.departemen; cout<<"Gaji : "; cin>>x.gaji; insertLast(&L, allocate(x)); cout<<endl; cout<<"Insert complete."; break; case 4: cout<<"ID : "; cin>>x.id; deleteFirst(&L, allocate(x)); cout<<endl; cout<<"Delete complete."; break; case 5: cout<<"ID: "; cin>>x.id; P = allocate(x); cout<<"Dimasukan setelah ID: "; cin>>x.id; Q = allocate(x); deleteAfter(&L, P, Q); cout<<endl; cout<<"Delete complete."; break; case 6: cout<<"ID: "; cin>>x.id; deleteFirst(&L, allocate(x)); cout<<endl; cout<<"Delete complete."; break; case 7: viewList(L); break; case 8: cout<<"ID: "; cin>>x.id; P = searchElement(&L, x); if(P != Nil) { cout<<"ID = "<<info(P).id<<endl; cout<<"Nama = "<<info(P).nama<<endl; cout<<"Jabatan = "<<info(P).jabatan<<endl; cout<<"Departemen = "<<info(P).departemen<<endl; cout<<"Gaji = "<<info(P).gaji<<endl; } else { cout<<"Data tidak ditemukan."; } break; case 9: cout<<"ID: "; cin>>x.id; P = searchSentinel(&L, x); if(P != Nil) { cout<<"ID = "<<info(P).id<<endl; cout<<"Nama = "<<info(P).nama<<endl; cout<<"Jabatan = "<<info(P).jabatan<<endl; cout<<"Departemen = "<<info(P).departemen<<endl; cout<<"Gaji = "<<info(P).gaji<<endl; } break; } } return 0; }