|
|
вернуться в форум1001. Reverse Root The following code is failing the test case 3, I have used linked-list to store the data in as a stack. Below is the code for reference, can you tell me where I am going wrong. Thank you. #include<stdio.h> #include<stdlib.h> #include<stdbool.h> #include<math.h> #include<assert.h> typedef unsigned long long _ull; typedef unsigned int _uint; typedef struct _link_list { _ull _number; struct _link_list*_next; } _list; void _makenode(_list**,_ull); void _insertnode(_list**,_list*); int main(int argc,const char*argv[]) { _ull _val; _list *_head,*_temp; _head = _temp = NULL; while(true) { fscanf(stdin,"%lld",&_val); assert(_val>=0); if(feof(stdin)) break; _makenode(&_head,_val); } while(_head) { _temp = _head; fprintf(stdout,"%0.4lf\n",sqrt(_head->_number)); _head = (_head->_next); free(_temp); } return 0; } void _makenode(_list**_ptr,_ull _data) { _list*_node = malloc(sizeof(_list)); (_node->_number) = _data; (_node->_next) = NULL; _insertnode(_ptr,_node); } void _insertnode(_list**_ptr,_list*_node) { if(!(*_ptr)) (*_ptr) = _node; else { (_node->_next) = (*_ptr); (*_ptr) = _node; } } |
|
|