fork download
  1. #include<iostream>
  2. #define N 100
  3.  
  4. using namespace std;
  5.  
  6.  
  7.  
  8. struct ListNode{
  9.  
  10. ListNode *link;
  11. bool tag;
  12. union{
  13. char data;
  14. ListNode *dlink;
  15. };
  16.  
  17. };
  18.  
  19. struct Stack{
  20. ListNode *stackarray[N];
  21. int sp;
  22.  
  23.  
  24. };
  25. Stack s;
  26.  
  27. int push(Stack *,ListNode *);
  28. ListNode* pop(Stack *);
  29. int isempty(Stack *);
  30. int isfull(Stack *);
  31. ListNode* create(char []);
  32.  
  33. int main(void){
  34. s.sp=-1;
  35.  
  36.  
  37. ListNode* h=NULL;
  38.  
  39. char input[50];
  40. cin>>input;
  41. h=create(input);
  42.  
  43. cout<<h->data<<endl;
  44.  
  45.  
  46. system("pause");
  47. return 0;
  48.  
  49.  
  50. }
  51.  
  52.  
  53. ListNode* create(char string[] ){
  54. ListNode *p=new ListNode;
  55. ListNode *q;
  56. int i=0;
  57. char x;
  58. x=string[i++];
  59.  
  60. do{
  61. switch(x){
  62. case '(':
  63. x=string[i++];
  64. p->tag=true;
  65. if(x==')'){
  66. p->dlink=NULL;
  67. if(!isempty(&s))
  68. x=string[i++];
  69.  
  70. }
  71. else{
  72. p->dlink=new ListNode;
  73. push(&s,p);
  74.  
  75. }
  76. break;
  77. case ')':
  78. p->link=NULL;
  79. p=pop(&s);
  80. if(!isempty(&s))
  81. x=string[i++];
  82. break;
  83.  
  84. case ',':
  85. p->link=new ListNode;
  86. p=p->link;
  87. x=string[i++];
  88. break;
  89.  
  90. default:
  91. p->tag=false;
  92. p->data=x-48;
  93. x=string[i++];
  94.  
  95. }
  96.  
  97.  
  98. }while(!isempty(&s));
  99.  
  100. q=p->dlink;
  101.  
  102. free(p);
  103. return q;
  104.  
  105.  
  106. }
  107.  
  108.  
  109. int push(Stack *p,ListNode *x){
  110. if(isfull(p))
  111. return 1;
  112. p->sp++;
  113. p->stackarray[p->sp]=x;
  114.  
  115. }
  116.  
  117. ListNode* pop(Stack *p){
  118. if(isempty(p))
  119. return NULL;
  120. else
  121. return p->stackarray[p->sp--];
  122.  
  123.  
  124. }
  125.  
  126. int isempty(Stack *p){
  127. if(p->sp==-1)
  128. return 1;
  129. else
  130. return 0;
  131. }
  132.  
  133. int isfull(Stack *p){
  134. if(p->sp==N-1)
  135. return 1;
  136. else
  137. return 0;
  138. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:46: error: ‘system’ was not declared in this scope
prog.cpp: In function ‘ListNode* create(char*)’:
prog.cpp:102: error: ‘free’ was not declared in this scope
stdout
Standard output is empty