node *deletenode(node *root,int data) { node *temp; if(root==NULL) printf("Element doesnot exist!!!"); else if(root->data > data) root->left=deletenode(root->left,data); else if(root->data < data) root->right=deletenode(root->right,data); else { if(root->left && root->right) { printf("\ntest"); temp=findmax(root->left); root->data=temp->data; root->left=deletenode(root->left,root->data); } else { temp=root; if(root->left) root=root->left; else if(root->right) root=root->right; else root=NULL; free(temp); } } return root; }
void main() { struct student *creatlink(); void printlink(struct student *head); void searchid(struct student *head,int m); struct student *insertnode(struct student *head,struct student *stud); struct student *deletenode(struct student *head,int m); struct student *sortid(struct student *head); void deletelink(struct student *head); struct student *head,*stu; int m; head=creatlink(); printlink(head); printf("input the student id you want\n"); scanf("%d",&m); searchid(head,m); printf("\n\nnow it's going to sort it\n\n"); sortid(head); printlink(head); printf("then insert a student record\n "); stu=(struct student *)malloc(LEN); printf("intput the student's id\n"); scanf("%d",&stu->num); printf("input the student's name\n"); scanf("%s",stu->name); printf("input the student's score\n"); scanf("%f",&stu->score); insertnode(head,stu); printlink(head); printf("now input the student you want to delete\n"); scanf("%d",&m); deletenode(head,m); printlink(head); deletelink(head); }
int main() { int n1,n2; Node *first,*second; Node *i; while(scanf_s("%d %d",&n1,&n2)!=EOF) { if(!n1&&!n2) { printf("NULL\n"); return 0; } for(int k=0;k<n1;k++) { Node *newNode=new Node; scanf_s("%d",&newNode->value); newNode->next=NULL; if(k==0) { first=newNode; i=first; } else { i->next=newNode; i=i->next; } } for(int k=0;k<n2;k++) { Node *newNode=new Node; scanf_s("%d",&newNode->value); newNode->next=NULL; if(k==0) { second=newNode; i=second; } else{ i->next=newNode; i=i->next; } } __printf(first); __printf(second); Node *result=merge(first,second); __printf(result); deletenode(result); //bug 没有delete干净 } return 0; }
int main() { int ch, val,pos; printf("\nEnter to the world of Link List:"); getch(); while(1) { system("cls"); printf("\n0 >Eixt\n1 >AddFirst \n2 >Insert \n3 >AddLast \n4 >DeleteFirst \n5 >DeleteNode \n6 >DeleteLast\n7 >Display \n9 >Print Reversly \n10 >Freelist \n"); scanf("%d", &ch); switch(ch) { case 0: exit(0); case 1: printf("\nEnter the number : "); scanf("%d", &val); addfirst(val); break; case 2: printf("\nEnter the number and position :"); scanf("%d%d", &val,&pos); insert(val,pos); break; case 3: printf("\nEnter the number : "); scanf("%d", &val); addlast(val); break; case 4: delfirst(); break; case 5: printf("\nEnter the position :"); scanf("%d",&pos); deletenode(pos); break; case 6: dellast(); break; case 7: display(); break; case 9: printrev(head); break; case 10: freelist(); break; default : printf("\nEnter the correct choice "); } getch(); } return 0; }
void gooutbyorder (void) { //顺便服务熄灯函数 TASKNODE task; task.floor = elevator.floor; task.spetask = in; deletenode (task); while (lightlock); lightlock = true; lightin.floor[elevator.floor] = false; lightlock = false; if (laststate == goingup) { if (lightout.down[config.floor] && laststate == goingup && elevator.floor == config.floor) { task.spetask = down; deletenode (task); while (lightlock); lightlock = true; lightout.down[elevator.floor] = false; lightlock = false; } task.spetask = up; deletenode (task); while (lightlock); lightlock = true; lightout.up[elevator.floor] = false; lightlock = false; } if (laststate == goingdown) { if (lightout.up[1] && laststate == goingdown && elevator.floor == 1) { task.spetask = up; deletenode (task); while (lightlock); lightlock = true; lightout.up[elevator.floor] = false; lightlock = false; } task.spetask = down; deletenode (task); while (lightlock); lightlock = true; lightout.down[elevator.floor] = false; lightlock = false; } }
static void recursedeletenode( btDbvt* pdbvt, btDbvtNode* node) { if(!node->isleaf()) { recursedeletenode(pdbvt,node->childs[0]); recursedeletenode(pdbvt,node->childs[1]); } if(node==pdbvt->m_root) pdbvt->m_root=0; deletenode(pdbvt,node); }
int main() { int item, n; struct node *head = createlist(); printlist(head); //scanf("%d", &n); deletenode(head->next->next); //printf("%d\n", item); printf("\n"); printlist(head); return 0; }
void delete_node (PNODE *n, int value) { PNODE node; if (n == NULL) return; node = find_node (*n, value); if ((*n)->value == value) { deletenode (n); } else if (value < (*n)->value) { delete_node (&((*n)->left), value); } else { delete_node(&((*n)->right), value); } }
node *deletenode(node *root, int data) { node *temp; if(root == NULL) return root; if(data < root->key) root->left = deletenode(root->left, data); else if(data > root->key) root->right = deletenode(root->right, data); else { if(root->left == NULL) { temp = root->right; free(root); return temp; } else if(root->right == NULL) { temp = root->left; free(root); return temp; } else { temp = root->right; while(temp->left != NULL) temp = temp->left; root->key = temp->key; root->right = deletenode(root->right, temp->key); return root; } } }
static btDbvtNode* removeleaf( btDbvt* pdbvt, btDbvtNode* leaf) { if(leaf==pdbvt->m_root) { pdbvt->m_root=0; return(0); } else { btDbvtNode* parent=leaf->parent; btDbvtNode* prev=parent->parent; btDbvtNode* sibling=parent->childs[1-indexof(leaf)]; if(prev) { prev->childs[indexof(parent)]=sibling; sibling->parent=prev; deletenode(pdbvt,parent); while(prev) { const btDbvtVolume pb=prev->volume; Merge(prev->childs[0]->volume,prev->childs[1]->volume,prev->volume); if(NotEqual(pb,prev->volume)) { prev=prev->parent; } else break; } return(prev?prev:pdbvt->m_root); } else { pdbvt->m_root=sibling; sibling->parent=0; deletenode(pdbvt,parent); return(pdbvt->m_root); } } }
int main(int argc, char const *argv[]) { node * head=createnodes(10); printf("原链表\n"); printnodes(head); insertnode(head,4,100); printf("插入2后链表\n"); printnodes(head); deletenode(head,2); printf("删除1后链表\n"); printnodes(head); //反序输出 printnodesf(head); freenodes(head); return 0; }
static void fetchleaves(btDbvt* pdbvt, btDbvtNode* root, tNodeArray& leaves, int depth=-1) { if(root->isinternal()&&depth) { fetchleaves(pdbvt,root->childs[0],leaves,depth-1); fetchleaves(pdbvt,root->childs[1],leaves,depth-1); deletenode(pdbvt,root); } else { leaves.push_back(root); } }
void gooutforfirst (void) { //先到先服务熄灯函数 while (lightlock); lightlock = true; switch (curtask.spetask) { case up: lightout.up[curtask.floor] = false; break; case down: lightout.down[curtask.floor] = false; break; case in: lightin.floor[curtask.floor] = false; break; } lightlock = false; deletenode (curtask); }
int main(void) { int i; node **L; if (sizeof(int) < 4) { puts("This code must be compiled with 32-bit ints!"); return EXIT_FAILURE; } L=newlist(); puts(" DOWN"); for(i = 100; i >= 0; i -=2) insertnode(L, i, i); puts(" UP"); for(i = 1; i < 100; i += 2) insertnode(L, i, i); deletenode(L, 40); puts(" FIND"); for(i = -2; i <= 100; ++i) findnode(L, i); puts(" FAST"); findall(L); puts("SAMPLES"); printf(" %d", findnode(L, -10)); printf(" %d,", findnode(L, 0)); printf(" %d", findnode(L, 1)); printf(" %d", findnode(L, 2)); printf(" %d", findnode(L, 39)); printf(" %d", findnode(L, 40)); printf(" %d", findnode(L, 41)); printf(" %d", findnode(L, 42)); puts(" DONE"); return EXIT_SUCCESS; }
void _tree () { bnode* root = NULL; root = insert(root, 10); insert(root, 20); insert(root, 30); insert(root, 11); insert(root, 13); insert(root, 15); insert(root, 40); insert(root, 90); inorder(root); printf ("\n deleting 90\n"); root = deletenode(root, 90); inorder(root); printf ("\n find 30 is %d\n", find(root, 300)->data); printf ("this is %s a bst\n",is_bst(root)?"":"not"); printf ("sum is %d\n",sum(root)); }
int StandardPrompt() { char command[20] = " "; char string[400]; char argument[400]; while (strcmp(command,"quit\n") != 0) { printf("\n"); printf("cmd: info, list-nodes, delete-node, quit\n"); printf("esp> "); fgets (string,400,stdin); strcpy(argument,string); strcpy(command,getCommand(string, command)); if(strcmp(command,"info\n")==0) { printf("-----------------------\n" "Version 0.1\n0664jester\n" "-----------------------\n"); } else if(strcmp(command,"quit\n")==0) { } else if(strcmp(command, "list-nodes\n")==0) { printList(); } else if (strcmp(command,"delete-node\n")==0) { deletenode(); } else { printf("command unknown.\n"); } } return 1; }
void main() { node *head; int i, data; head=createnode();//head has no real data for(i=0; i<20; i++) { data = rand() % 100; addnode(head, data); } printnodes(head); revert(head); printnodes(head); deletenode(head); head = NULL; return; }
void main() { char ans='n'; printf("Want to create a BST (y/n) ? :"); scanf("%c",&ans); node *root=NULL; int data=0,count=0,k=0; while(ans=='y') { node *new_node; printf("\nEnter the element = "); scanf("%d",&data); new_node=get_node(data); if(root==NULL) root=new_node; else insert(root,new_node,data); printf("\nWant to add more elements(y/n)? : "); ans=getch(); } printf("\nThe BST created is: "); display(root); printf("\nsmallest node= %d",findmin(root)->data); printf("\nlargest node= %d",findmax(root)->data); printf("\nEnter the value of k for kth smallest node = "); scanf("%d",&k); findkthsmallest(root,k); printf("\nDo you want to delete a node (y/n)? :"); ans=getch(); if(ans=='y') { printf("\nEnter the element you want to delete = "); scanf("%d",&data); root=deletenode(root,data); printf("\nThe BST after deletion is: "); display(root); } }
int main(void) { int val, len, pos; printf("How Many elements you want in your Linked list? \n"); scanf(" %d", &len); //Make randomisation independent of fixed system seed srand(time(NULL)); for(int i=1; i<=len; i++) { val = rand() % 10; insertnode(val, i); printf("your list is : "); printnode(); } puts("Enter Your Desired Position to delete"); scanf(" %d", &pos); deletenode(pos); printf("\nyour list is now : "); printnode(); return 0; }
/* ----------删除链表中第i个节点类用例------------- */ void CExampleTest::TestCase03_1() { struct strlnode *p; create(&p, 1); insertnode(&p, 1, 2); insertnode(&p, 2, 3); insertnode(&p, 3, 4); deletenode(&p, 2); CPPUNIT_ASSERT(p->data == 1); p = p->pnext; CPPUNIT_ASSERT(p->data == 2); p = p->pnext; CPPUNIT_ASSERT(p->data == 4); CPPUNIT_ASSERT(p->pnext == null); p = p->plast; CPPUNIT_ASSERT(p->data == 2); p = p->plast; CPPUNIT_ASSERT(p->data == 1); CPPUNIT_ASSERT(p->plast == null); }
int main(int argc, char const *argv[]) { int num; int data,pos; bool flag = FALSE; DLinkList pnode; DLinkList list = createlist(0); while(flag == FALSE) { printf("Main Menu\n"); printf("1. Insert\n"); printf("2. Delete Node\n"); printf("3. Find\n"); printf("4. Length\n"); printf("5. Positive print\n"); printf("6. Negative print\n"); printf("7. Delete list\n"); printf("8. Insert data where are you hope\n"); scanf("%d",&num); switch(num) { case 1: printf("Input the data to Insert:\n"); scanf("%d",&data); list = create(list,data); printlist(list); printf("\n");break; case 2: printf("Input the data to Delete:\n"); scanf("%d",&data); deletenode(list,data); printlist(list); printf("\n");break; case 3: printf("Input the data to Find:\n"); scanf("%d",&data); pnode = findnode(list,data); if (NULL != pnode) { printf("find succeed! position is %d\n",pnode->data); printf("\n"); } else{ printf("Find failed\n"); printf("\n"); } break; case 4: printf("The list's length is %d\n",getlength(list)); printf("\n");break; case 5: printlist(list); //printf("\n"); break; case 6: reverprint(list); printf("\n");break; case 7: deletelist(list); printf("\n");break; case 8: printf("Input the data to Insert:\n"); scanf("%d,%d",&pos,&data); list = crdata(list,pos,data); printlist(list); printf("\n");break; case 0: deletelist(list); flag = TRUE; } } return 0; }
void btDbvt::remove(btDbvtNode* leaf) { removeleaf(this,leaf); deletenode(this,leaf); --m_leaves; }
main(){ nd *head=NULL, *temp; char input[256], inputcopy[256], word[20], result[20];; int jump, cnt, numofDigits; char delim, *a, * token; char wordcopy[20], tempword[20], dashed[20], prev[20]; int numdash; // ------ int i, cnter, num, j, dash, hundflag=0, thouflag=0, hundthouone=0; printf("enter words : "); fgets(input, sizeof(input), stdin); input[ strlen(input) - 1 ] = '\0'; strncpy ( inputcopy, input, 256); a = strtok (input," -"); strncpy( word, a, 20); while(a!=NULL ){ //loops throught the words // strncpy( word, a, 20); if (strcmp (word, "thousand") == 0 ){ //ignores the word "thousand" but sets its flag; does not insert something in the list thouflag =1; } else if( strcmp (word, "hundred") == 0){ hundflag =1; //ignores the word "hundred" but sets its flag; does not insert something in the list }else if( strcmp (word, "million") == 0){ //ignores the word "million" but sets its flag; does not insert something in the list }else{ //if word is not thousand, hundred or million, it finds it in the fucntion // zero to nine and returns its equivalent digit if (numofDigits>1) hundthouone =1; num = zerotonine(word); if ( num == 66){ printf("Wrong input. enter again.\n"); exit(0); }else if (num == 69) exit(0); insert(&head, temp, num); numofDigits++; } a = strtok (NULL , " -"); if (a!= NULL ) { //takes note of the prev and current word strncpy ( prev, word, 20); strncpy( word, a, 20); } num =0; } //checks of the last word is thousand, hundred or million to add the zeroes if (( strcmp (word, "thousand") == 0 || strcmp (word, "hundred") == 0 || strcmp (word, "million") == 0 ) && a==NULL ){ int a, times; if (strcmp (word, "thousand") == 0){ if (hundflag ==1 && thouflag ==1 ){//three hundred thousand //300000 times =5; }else { // 326 000 // three hundred twenty-six thousand //22 0000 //thirty thousand times = 3; } if ( checkty(prev) == 1){ times = times +1; } }else if (strcmp (word, "hundred") == 0){ // printf("hundred diri \n"); times= 2; }else if (strcmp (word, "million") == 0){ times = 6; } for (a = 0; a < times; a++){ insert(&head, temp, 0); numofDigits++; } } //checks of 1001 801 or the like, if the number has zeroes between it if ( strcmp (prev, "hundred") == 0 || strcmp (prev, "thousand") == 0 ){ int b, x, tempnum; tempnum = getlast(&head); deletenode(&head); if (strcmp (prev, "thousand") == 0 ) x=2; if (strcmp (prev, "hundred") == 0 ) x=1; for (b= 0;b < x; b++){ insert(&head, temp, 0); numofDigits++; } insert(&head, temp, tempnum); } //checks of last word ends in -ty if ( checkty(word) == 1 || (checkty(word) == 1 && strcmp (prev, "hundred") == 0)){ insert(&head, temp, 0); numofDigits++; } display(head); printf("\n\n"); free(head); }