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); 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: return 0; } /*scanf("%d",&input); Add(&aaa,input); Print(&aaa);*/ return 0; }
run
|
edit
|
history
|
help
0
FunPointBreakfast
MailingList
Stub Program for Problem 6 HW 2
Lab 11
sizeof human
GCC supports 128-bit integer arithmetic
Fgets and String Stuff
C_141210_Punteros
dynamic memory allocation.c
Operation of two numbers