fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. struct sdp{
  6.  
  7. int num;
  8.  
  9. struct sdp *ps;
  10. struct sdp *pd;
  11.  
  12.  
  13. };
  14.  
  15. struct sdp* fcl(int ns);
  16. void fs(struct sdp *pst);
  17.  
  18.  
  19.  
  20. int main(void) {
  21.  
  22.  
  23. struct sdp *ps;
  24.  
  25. ps=fcl(5);
  26.  
  27. fs(ps);
  28.  
  29.  
  30. return 0;
  31. }
  32.  
  33.  
  34.  
  35. struct sdp* fcl(int ns){
  36.  
  37. struct sdp *ps1,*ps2;
  38.  
  39. ps1=(struct sdp*)malloc(sizeof(struct sdp));
  40.  
  41. ps1->num=ns;
  42.  
  43. ps1->pd=NULL;
  44.  
  45. while(ns>1){
  46.  
  47. ns--;
  48.  
  49. ps2=(struct sdp*)malloc(sizeof(struct sdp));
  50.  
  51. ps1->ps=ps2;
  52.  
  53. ps2->num=ns;
  54.  
  55. ps2->pd=ps1;
  56.  
  57. ps1=ps2;
  58.  
  59. }
  60.  
  61. ps1->ps=NULL;
  62.  
  63. return ps1;
  64.  
  65. }
  66.  
  67.  
  68. void fs(struct sdp *pst){
  69.  
  70.  
  71. while(pst!=NULL){
  72.  
  73. printf("%d\n",pst->num);
  74. printf("%d\n",pst->ps);
  75. printf("%d\n",pst->pd);
  76. printf("%d\n",pst);
  77. printf("\n\n");
  78.  
  79. pst=pst->pd;
  80.  
  81. }
  82.  
  83.  
  84.  
  85. }
  86.  
  87.  
Success #stdin #stdout 0s 5560KB
stdin
Standard input is empty
stdout
1
0
1626849984
1626850016


2
1626850016
1626849952
1626849984


3
1626849984
1626849920
1626849952


4
1626849952
1626849888
1626849920


5
1626849920
0
1626849888