fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include<stdlib.h>
  4. struct node
  5. {
  6. char ch;
  7. struct node * next;
  8. };
  9. int listSize=0;
  10. struct node* stackHead=NULL;
  11. struct node* queueHead=NULL;
  12. struct node* queuetail=NULL;
  13. //----------------------------------
  14. void push(char c)
  15. {
  16. struct node *new=(struct node *)malloc(sizeof(struct node));
  17. //if(new==NULL){printf("NOT\n");}
  18. new->ch=c;
  19. new->next=stackHead;
  20. stackHead=new;
  21. listSize++;
  22. }
  23. //------------------------------
  24. char pop()
  25. {
  26. struct node* current=stackHead;
  27. char z;
  28. //if(stackHead==NULL){printf("error");}
  29. stackHead=current->next;
  30. z=current->ch;
  31. free(current);
  32. listSize--;
  33. return z;
  34. }
  35.  
  36. //------------------------------
  37. void enqueue(char c)
  38. {
  39. struct node* new;
  40. new=(struct node *)malloc(sizeof(struct node));
  41. new->next=NULL;
  42. //if(new==NULL){printf("NOT\n");}
  43. new->ch=c;
  44. new->next=NULL;
  45. if((queueHead==NULL)&&(queuetail==NULL))
  46. {
  47. queueHead=new;
  48. queuetail=new;
  49. listSize++;
  50. }
  51. else
  52. {
  53. queuetail->next=new;
  54. queuetail=new;
  55. listSize++;
  56. }
  57. }
  58. //-----------------------------------------------------
  59. char dequeue()
  60. {
  61. if((queueHead==NULL)&&(queuetail==NULL)){ printf("empty\n");
  62. return 0;}
  63. else
  64. {
  65. struct node* tmp1=queueHead;
  66. queueHead=queueHead->next;
  67. char w;
  68. w=tmp1->ch;
  69. free(tmp1);
  70. listSize--;
  71. return w;
  72. }
  73. }
  74. //----------------------------------
  75. int isEmpty()
  76. {
  77. int z;
  78. if(stackHead==NULL)
  79. {
  80. z=1;
  81. }
  82. else
  83. {
  84. z=0;
  85. }
  86. return z;
  87. }
  88. //------------------------------------
  89.  
  90. int main()
  91. {
  92. char stackChar;
  93. char queueChar;
  94. char x;
  95. int i,length;
  96. //int ispalindrome;
  97. scanf("%d",&length);
  98. int y=1;
  99. for(i=0;i<length;i++)
  100. {
  101. while(y==scanf("%c",&x))
  102. {
  103. if(x !=' '){
  104. push(x);
  105. enqueue(x);
  106. }
  107.  
  108. }
  109.  
  110. while (!isEmpty(&stackHead))
  111. {
  112. stackChar=pop();
  113. queueChar=dequeue();
  114. printf("%c",stackChar);
  115. /*if (stackChar==queueChar)
  116. {
  117. ispalindrome= 1;
  118. printf("%c %c\n",stackChar,queueChar);
  119. }
  120. else
  121. {
  122. ispalindrome = 0;
  123. printf("%c %c\n",stackChar,queueChar);
  124. break;
  125. }*/
  126. }
  127. #include <stdio.h>
  128. #include <string.h>
  129. #include<stdlib.h>
  130. struct node
  131. {
  132. char ch;
  133. struct node * next;
  134. };
  135. int listSize=0;
  136. struct node* stackHead=NULL;
  137. struct node* queueHead=NULL;
  138. struct node* queuetail=NULL;
  139. //----------------------------------
  140. void push(char c)
  141. {
  142. struct node *new=(struct node *)malloc(sizeof(struct node));
  143. //if(new==NULL){printf("NOT\n");}
  144. new->ch=c;
  145. new->next=(*stackHead);
  146. (*stackHead)=new;
  147. listSize++;
  148. }
  149. //------------------------------
  150. char pop()
  151. {
  152. struct node* current;
  153. char z;
  154. current= *stackHead;
  155. //if(stackHead==NULL){printf("error");}
  156. assert(current != NULL);
  157. z=current->ch;
  158. *stackHead = current->next;
  159. free(current);
  160. listSize--;
  161. return z;
  162. }
  163.  
  164. //------------------------------
  165. void enqueue(char c)
  166. {
  167. struct node* new;
  168. new=(struct node *)malloc(sizeof(struct node));
  169. new->next=NULL;
  170. //if(new==NULL){printf("NOT\n");}
  171. new->ch=c;
  172. new->next=NULL;
  173. if((queueHead==NULL)&&(queuetail==NULL))
  174. {
  175. queueHead=new;
  176. queuetail=new;
  177. listSize++;
  178. }
  179. else
  180. {
  181. queuetail->next=new;
  182. queuetail=new;
  183. listSize++;
  184. }
  185. }
  186. //-----------------------------------------------------
  187. char dequeue()
  188. {
  189. if((queueHead==NULL)&&(queuetail==NULL)){ printf("empty\n");
  190. return 0;}
  191. else
  192. {
  193. struct node* tmp1=queueHead;
  194. queueHead=queueHead->next;
  195. char w;
  196. w=tmp1->ch;
  197. free(tmp1);
  198. listSize--;
  199. return w;
  200. }
  201. }
  202. //----------------------------------
  203. int isEmpty()
  204. {
  205. int z;
  206. if(stackHead==NULL)
  207. {
  208. z=1;
  209. }
  210. else
  211. {
  212. z=0;
  213. }
  214. return z;
  215. }
  216. //------------------------------------
  217.  
  218. int main()
  219. {
  220. char stackChar;
  221. char queueChar;
  222. char x;
  223. int i,length;
  224. //int ispalindrome;
  225. scanf("%d",&length);
  226. int y=1;
  227. for(i=0;i<length;i++)
  228. {
  229. while(y==scanf("%c",&x))
  230. {
  231. if(x !=' '){
  232. push(x);
  233. enqueue(x);
  234. }
  235.  
  236. }
  237.  
  238. while (!isEmpty(&stackHead))
  239. {
  240. stackChar=pop();
  241. queueChar=dequeue();
  242. printf("%c",stackChar);
  243. /*if (stackChar==queueChar)
  244. {
  245. ispalindrome= 1;
  246. printf("%c %c\n",stackChar,queueChar);
  247. }
  248. else
  249. {
  250. ispalindrome = 0;
  251. printf("%c %c\n",stackChar,queueChar);
  252. break;
  253. }*/
  254. }
  255. printf("\n...\n");
  256. //printf("%d\n",ispalindrome);
  257. }
  258. }
  259.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
cc1: warnings being treated as errors
prog.c: In function ‘main’:
prog.c:140: error: ISO C forbids nested functions
prog.c: In function ‘push’:
prog.c:145: error: incompatible types in assignment
prog.c:146: error: incompatible types in assignment
prog.c: In function ‘main’:
prog.c:150: error: ISO C forbids nested functions
prog.c: In function ‘pop’:
prog.c:154: error: incompatible types in assignment
prog.c:156: error: implicit declaration of function ‘assert’
prog.c:158: error: incompatible types in assignment
prog.c: In function ‘main’:
prog.c:165: error: ISO C forbids nested functions
prog.c:187: error: ISO C forbids nested functions
prog.c:203: error: ISO C forbids nested functions
prog.c:218: error: ISO C forbids nested functions
prog.c:218: error: ‘main’ is normally a non-static function
prog.c:258: error: expected declaration or statement at end of input
prog.c:258: error: expected declaration or statement at end of input
stdout
Standard output is empty