PHP Code:
/***
* _ _
* (_) (_)
* __ ____ _ _ _____ ___ ___ ___ ___ _ __ ___
* \ \/ / _` | |/ _ \ \ / / |/ _ \ / __/ _ \| '_ ` _ \
* > < (_| | | (_) \ V /| | (_) | (_| (_) | | | | | |
* /_/\_\__, |_|\___/ \_/ |_|\___(_)___\___/|_| |_| |_|
* __/ |
* |___/
*/
#include <st***.h>
#include <stdlib.h>
#include <string.h>
typedef struct member {
char* name;
char* surname;
struct member * next;
}member_struct;
member_struct * loop_delete_node_from_and_count (char * keyword, member_struct * members, int *count, int * all_list);
member_struct * delete_node_from_and_count (char * keyword, member_struct * members, int *count, int * all_list);
///////////////////////////////////////////////////////////////// begin
int main (void){
char * keyword;
int count =0;
int all_list= 0;
member_struct members[10]={
{"gino","carol",(members+1)},
{"mario","fonz",(members+2)},
{"fonzo","cristina",(members+3)},
{"alberto","marcopolo",(members+4)},
{"ndonio","paolo",(members+5)},
{"fonzetto","paolone",(members+6)},
{"mario","paolino",(members+7)},
{"assunta","paols",(members+8)},
{"giovanni","mario",(members+9)},
{"ann","ponzio",NULL}
};
member_struct *list;
////////////////////////////////////////////////////////////// end of init
list = members;
keyword="mario";
//////////////////////// loop delete until all list scanned
list = loop_delete_node_from_and_count (keyword,members,&count,&all_list);
// keyword is the string to compare
// members is the list name
// &count is the return address to write delete actions number
// &all_list is the return address to confirm a complete list scan
//////////////////////// print
if (count){
printf("Nodo eliminato %d volte\n",count);
}else{
printf("Nodo non trovato");
}
}
////////////////////////////////////////////////// functions
////////////////////////////////////////////////////////////////////////loop wrapper for delete_node_from_and_count
member_struct * loop_delete_node_from_and_count (char * keyword, member_struct * members, int *count, int * all_list){
for(;*all_list==0;){
delete_node_from_and_count (keyword,members,count,all_list);
}
}
///////////////////////////////////////////////////////////////////// delete a node and return the new list
member_struct * delete_node_from_and_count (char * keyword, member_struct * members, int *count, int * all_list){
if (members==NULL){
*all_list=1;
return NULL;
}
if (keyword == members->name || keyword == members->surname){
*count+=1;
return members->next;
}
members->next = delete_node_from_and_count (keyword,members->next,count,all_list);
return members;
}