Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
LinkedListTest
//gcc 4.9.3 #include <stdio.h> #include <stdlib.h> struct node{ int val; struct node *next; }; void Add(struct node *head, int val){ struct node *new = (struct node *)malloc(sizeof(struct node)); new->val = val; new->next = NULL; //struct node *tmp = head; while(head->next){ head = head->next; } head->next = new; } int Del(struct node *head, int num){ struct node *tmp, *pre; tmp = head; while(tmp){ if(tmp->val == num){ if(tmp == head){ head = tmp->next; free(tmp); tmp = NULL; return 1; } else{ pre->next = tmp->next; free(tmp); tmp = NULL; return 1; } } else{ pre = tmp; tmp = tmp->next; } } return 0; } void Print(struct node* head){ while(head){ printf("%d ",head->val); head = head->next; } } int main(void) { struct node aaa; aaa.val = 5; aaa.next = NULL; int input = 0; int choice; printf("Please input the choice : "); scanf("%d",&choice); while(choice<4){ switch(choice){ case 1: printf("Please input the data : "); scanf("%d",&input); Add(&aaa,input); printf("\n"); break; case 2: printf("Please select the node which deleted : "); scanf("%d",&input); Del(&aaa,input); printf("\n"); break; case 3: Print(&aaa); printf("\n"); break; default: break; } scanf("%d",&choice); } /*scanf("%d",&input); Add(&aaa,input); Print(&aaa);*/ return 0; }
run
|
edit
|
history
|
help
0
test
Critical Openmp Example
linux (mostly) true random number generator
C pattern Rhombus
B_141125_Repetidos
MatrixMul_shortxshort
guia 4 terminada
ChangeStructVal
formatting_input_and_output
20171117_TARTAGLIA