fork download
  1. // sennkei list
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. typedef struct node {
  7. int val;
  8. struct node *next;
  9. }Node;
  10.  
  11. Node *head = NULL;
  12.  
  13. Node* createN(int x){
  14. Node *newnode;
  15. newnode = (Node *)malloc(sizeof(Node));
  16. newnode->val = x;
  17. newnode->next = NULL;
  18. return newnode;
  19. }
  20.  
  21. void initL(int n){
  22. int x,i;
  23. Node *p;
  24. scanf("%d",&x);
  25. head = createN(x);
  26. p = head;
  27. for(i=1;i<n;i++){
  28. scanf("%d",&x);
  29. p->next = createN(x);
  30. p = p->next;
  31. }
  32. }
  33.  
  34. void freeL(){
  35. Node *p;
  36. while(head!=NULL){
  37. p = head->next;
  38. free(head);
  39. head = p;
  40. }
  41. }
  42.  
  43. void printN(Node *a){
  44. if(a == NULL) printf("NULL\n");
  45. else printf("%d\n",a->val);
  46. }
  47.  
  48. void printL(){
  49. Node *p = head;
  50. while(p != NULL){
  51. printf("%d ",p->val);
  52. p = p->next;
  53. }
  54. printf("\n");
  55. }
  56.  
  57. Node* getN(int n){
  58. int i;
  59. Node *p;
  60. p = head;
  61. for(i=1;i<n;i++) p = p->next;
  62. return p;
  63. }
  64.  
  65. int countL(){
  66. int ret = 0;
  67. Node *p = head;
  68. while(p!=NULL){
  69. p = p->next;
  70. ret++;
  71. }
  72. return ret;
  73. }
  74.  
  75. Node* searchX(int x){
  76. Node *p;
  77. for(p=head; p!=NULL; p=p->next){
  78. if(p->val == x) break;
  79. }
  80. return p;
  81. }
  82.  
  83. void insHead(int x){
  84. Node *p; //1
  85. p = createN(x); //1
  86. p->next = head; //2
  87. head = p; //3
  88. }
  89.  
  90. void insMiddle(int n, int x){
  91. int i;
  92. Node *p,*q;
  93. p = head; //1
  94. for(i=1;i<n;i++){ //2
  95. p = p->next; //2
  96. }
  97. q = createN(x); //3
  98. q->next = p->next; //4
  99. p->next = q; //5
  100. }
  101.  
  102. void insTail(int x){
  103. Node *p;
  104. p = head; //1
  105. if(p==NULL){
  106. head = createN(x);
  107. return;
  108. }
  109. while(p->next != NULL){ //2
  110. p = p->next; //2
  111. }
  112. p->next = createN(x); //3
  113. }
  114.  
  115. void delHead(){
  116. Node *p;
  117. p = head; //1
  118. head = head->next; //2
  119. free(p); //3
  120. }
  121.  
  122. void delMiddle(int n){
  123. int i;
  124. Node *p,*q;
  125. p = head; //1
  126. for(i=1;i<n-1;i++){ //2
  127. p = p->next; //2
  128. }
  129. q = p->next; //3
  130. p->next = q->next; //4
  131. free(q); //5
  132. }
  133.  
  134. void delTail(){
  135. Node *p;
  136. p = head; //1
  137. while(p->next->next != NULL){ //2
  138. p = p->next; //2
  139. }
  140. free(p->next); //3
  141. p->next = NULL; //4
  142. }
  143.  
  144. void push(int x){
  145. //ここに書く
  146. }
  147.  
  148. int pop(){
  149. //ここに書く
  150. }
  151.  
  152. void enqueue(int x){
  153. //ここに書く
  154. }
  155.  
  156. int dequeue(){
  157. //ここに書く
  158. }
  159.  
  160. int main(void){
  161. int s1,s2,s3,q1,q2,q3;
  162.  
  163. push(1);
  164. push(2);
  165. push(3);
  166. s1 = pop();
  167. s2 = pop();
  168. s3 = pop();
  169. printf("%d %d %d\n",s1,s2,s3);
  170.  
  171. //キュー
  172. enqueue(1);
  173. enqueue(2);
  174. enqueue(3);
  175. q1 = dequeue();
  176. q2 = dequeue();
  177. q3 = dequeue();
  178. printf("%d %d %d\n",q1,q2,q3);
  179.  
  180. freeL();
  181. return 0;
  182. }
  183.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
0 0 0
0 0 0