Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. PELEM * Create(int n)
  2. {
  3. PELEM *L=(PELEM*)calloc(1,sizeof(PELEM));
  4. L->data=n;
  5. L->next=NULL;
  6. return L;
  7. }
  8. void Destroy(PELEM * L)
  9. {
  10. free(L);
  11. L=NULL;
  12. }
  13. PELEM* CreateL()
  14. {
  15. return NULL;
  16. }
  17. void DestroyL(PELEM*L)
  18. {
  19. if(L->next==NULL)
  20. {
  21. Destroy(L);
  22. }
  23. else
  24. {
  25. DestroyL(L->next);
  26. Destroy(L);
  27. }
  28.  
  29. }
  30. PELEM * insertFirst(PELEM *L,int n)
  31. {
  32. PELEM *K;
  33. K=Create(n);
  34. K->next=L;
  35. return K;
  36. }
  37. PELEM * insertLast(PELEM *L,int n)
  38. {
  39. PELEM *K;
  40. PELEM *S;
  41. K=Create(n);
  42. if(L==NULL)
  43. {
  44. return K;
  45. }
  46. S=L;
  47. while(L->next!=NULL)
  48. {
  49. L=L->next;
  50. }
  51. L->next=K;
  52. return S;
  53. }
  54. PELEM * insertOrdered(PELEM *L,int n)
  55. {
  56. PELEM *K;
  57. PELEM *S;
  58. PELEM *seged;
  59. K=Create(n);
  60. if(L==NULL)
  61. {
  62. return K;
  63. }
  64. S=L;
  65. if(K->data<L->data)
  66. {
  67. K->next=L;
  68. return K;
  69. }
  70. if(L->next!=NULL){
  71. while(K->data>L->next->data)
  72. {
  73. L=L->next;
  74. if(L->next==NULL)
  75. {
  76. L->next=K;
  77. return S;
  78. }
  79.  
  80. }}
  81. seged=L->next;
  82. K->next=seged;
  83. L->next=K;
  84. return S;
  85.  
  86. }
  87. PELEM * SortL(PELEM *L)
  88. {
  89. if(L->next==NULL)
  90. {
  91. return L;
  92. }
  93. PELEM * S;
  94. S=L;
  95. int seged;
  96. int csere=1;
  97. while(csere)
  98. {
  99. csere=0;
  100. L=S;
  101. while(L->next!=NULL)
  102. {
  103. if(L->data>L->next->data)
  104. {
  105. seged=L->next->data;
  106. L->next->data=L->data;
  107. L->data=seged;
  108. csere=1;
  109. }
  110. L=L->next;
  111. }
  112. }
  113. return S;
  114. }
  115.  
  116.  
  117. void Print(PELEM *L)
  118. {
  119. while(L!=NULL)
  120. {
  121. printf("%d ",L->data);
  122. L=L->next;
  123. }
  124. printf("\n");
  125. }
  126. PELEM * Delete(PELEM *L,int n){
  127. PELEM *Seged;
  128. PELEM *S;
  129. S=L;
  130. if(L->data==n){
  131. S=L->next;
  132. Destroy(L);
  133. return S;
  134. }
  135. while(L->next!=NULL){
  136. if(L->next->data==n){
  137. Seged=L->next;
  138. L->next=Seged->next;
  139. Destroy(Seged);
  140. return S;
  141. }
  142. L=L->next;
  143. }
  144. return S;
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement