Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- struct lista_trig
- {
- double (*fun)(double);
- char *fnm;
- struct lista_trig * next;
- };
- void ADD_END(struct lista_trig **head , char fun_name[3] , double (*fun_ptr)(double));
- void FREE_LIST_ITERATIVE(struct lista_trig **head);
- void PRINTF_LIST_RECURSIVE(struct lista_trig *head, double value_deg);
- int main(void)
- {
- char fun_name[3][4] = {{"sin"}, {"cos"}, {"tan"}};
- double (*fun_ptr[3])(double) = { sin, cos, tan };
- struct lista_trig * head = NULL;
- int i;
- printf("DODAJE NA KONIEC\n");
- for(i=0; i<3; i++)
- {
- ADD_END(&head, fun_name[i], fun_ptr[i]);
- }
- printf("\nWYPISUJE REKURENCYJNIE\n");
- double value_deg = 0;
- while(value_deg<90)
- {
- PRINTF_LIST_RECURSIVE(head,value_deg);
- value_deg += 30;
- }
- printf("\nZWALNIAM ITERACYJNIE\n");
- FREE_LIST_ITERATIVE(&head);
- return 0;
- }
- void ADD_END(struct lista_trig **head , char fun_name[3] , double (*fun_ptr)(double))
- {
- struct lista_trig *temp = (struct lista_trig*)malloc(sizeof(struct lista_trig)) ;
- if(!temp)
- {
- printf("MALLOC ERROR!\n");
- exit(-1);
- }
- temp->fun = fun_ptr;
- temp->fnm = fun_name;
- temp->next = NULL;
- if(*head)
- {
- struct lista_trig *tmp = *head;
- for(;tmp->next;)
- {
- tmp = tmp->next;
- }
- tmp->next = temp;
- }
- else
- {
- *head = temp;
- }
- }
- void PRINTF_LIST_RECURSIVE (struct lista_trig *head, double value_deg)
- {
- struct lista_trig *temp = head;
- printf("c:%p, c->%p, %s(%.0lf)=%lf \n", temp, temp->next, temp->fnm, value_deg, temp->fun(value_deg/180*M_PI));
- temp=temp->next;
- if(temp==NULL)
- PRINTF_LIST_RECURSIVE(temp,value_deg);
- }
- void FREE_LIST_ITERATIVE(struct lista_trig**head)
- {
- struct lista_trig *temp=*head;
- struct lista_trig *tmp;
- while(temp->next!=NULL)
- {
- tmp=temp->next;
- free(temp);
- temp=tmp->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement