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=stackHead;
  153. char z;
  154. //if(stackHead==NULL){printf("error");}
  155. stackHead=current->next;
  156. z=current->ch;
  157. free(current);
  158. listSize--;
  159. return z;
  160. }
  161.  
  162. //------------------------------
  163. void enqueue(char c)
  164. {
  165. struct node* new;
  166. new=(struct node *)malloc(sizeof(struct node));
  167. new->next=NULL;
  168. //if(new==NULL){printf("NOT\n");}
  169. new->ch=c;
  170. new->next=NULL;
  171. if((queueHead==NULL)&&(queuetail==NULL))
  172. {
  173. queueHead=new;
  174. queuetail=new;
  175. listSize++;
  176. }
  177. else
  178. {
  179. queuetail->next=new;
  180. queuetail=new;
  181. listSize++;
  182. }
  183. }
  184. //-----------------------------------------------------
  185. char dequeue()
  186. {
  187. if((queueHead==NULL)&&(queuetail==NULL)){ printf("empty\n");
  188. return 0;}
  189. else
  190. {
  191. struct node* tmp1=queueHead;
  192. queueHead=queueHead->next;
  193. char w;
  194. w=tmp1->ch;
  195. free(tmp1);
  196. listSize--;
  197. return w;
  198. }
  199. }
  200. //----------------------------------
  201. int isEmpty()
  202. {
  203. int z;
  204. if(stackHead==NULL)
  205. {
  206. z=1;
  207. }
  208. else
  209. {
  210. z=0;
  211. }
  212. return z;
  213. }
  214. //------------------------------------
  215.  
  216. int main()
  217. {
  218. char stackChar;
  219. char queueChar;
  220. char x;
  221. int i,length;
  222. //int ispalindrome;
  223. scanf("%d",&length);
  224. int y=1;
  225. for(i=0;i<length;i++)
  226. {
  227. while(y==scanf("%c",&x))
  228. {
  229. if(x !=' '){
  230. push(x);
  231. enqueue(x);
  232. }
  233.  
  234. }
  235.  
  236. while (!isEmpty(&stackHead))
  237. {
  238. stackChar=pop();
  239. queueChar=dequeue();
  240. printf("%c",stackChar);
  241. /*if (stackChar==queueChar)
  242. {
  243. ispalindrome= 1;
  244. printf("%c %c\n",stackChar,queueChar);
  245. }
  246. else
  247. {
  248. ispalindrome = 0;
  249. printf("%c %c\n",stackChar,queueChar);
  250. break;
  251. }*/
  252. }
  253. struct node* stackHead=NULL;
  254. struct node* queueHead=NULL;
  255. struct node* queuetail=NULL;
  256. printf("\n...\n");
  257. //printf("%d\n",ispalindrome);
  258. }
  259. }
  260.  
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:150: error: ISO C forbids nested functions
prog.c:163: error: ISO C forbids nested functions
prog.c:185: error: ISO C forbids nested functions
prog.c:201: error: ISO C forbids nested functions
prog.c:216: error: ISO C forbids nested functions
prog.c:216: error: ‘main’ is normally a non-static function
prog.c: In function ‘main’:
prog.c:255: error: unused variable ‘queuetail’
prog.c:254: error: unused variable ‘queueHead’
prog.c:253: error: unused variable ‘stackHead’
prog.c: In function ‘main’:
prog.c:259: error: expected declaration or statement at end of input
prog.c:259: error: expected declaration or statement at end of input
stdout
Standard output is empty