Guest User

Untitled

a guest
Jan 29th, 2014
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<ctype.h>
  5.  
  6. #define elementtype char
  7. #define labeltype char
  8. #define LAMBDA NULL
  9. typedef struct celltag1
  10. {
  11. elementtype element;
  12. struct celltag1 *next;
  13. } celltype1;
  14.  
  15. typedef struct _cell
  16. {
  17. labeltype label;
  18. struct _cell *leftchild, *rightchild;
  19. } celltype;
  20.  
  21. typedef celltype1 *List;
  22. typedef celltype1 *position;
  23.  
  24.  
  25.  
  26.  
  27. position LiEnd(List L)
  28. {
  29. position q;
  30. q = L;
  31. while (q->next != NULL)
  32. q = q->next;
  33. return q;
  34. }
  35.  
  36. int jesuma(int n)
  37. {
  38. int i=2; int k=2;
  39. for(i=2;i<n;k=2*k){
  40. i=i+k;
  41. }
  42. if(i==n)return 1;
  43. else return 0;
  44. }
  45.  
  46. position LiMakeNull(List *Lp)
  47. {
  48. *Lp = (celltype1*)malloc(sizeof(celltype1));
  49. (*Lp)->next = NULL;
  50. return (*Lp);
  51. }
  52.  
  53. void LiInsert(elementtype x, position p, List *Lp)
  54. {
  55. position temp;
  56. temp = p->next;
  57. p->next = (celltype1*)malloc(sizeof(celltype1));
  58. p->next->element = x;
  59. p->next->next = temp;
  60. }
  61.  
  62. void LiDelete(position p, List *Lp)
  63. {
  64. position temp;
  65. temp = p->next;
  66. p->next = p->next->next;
  67. free(temp);
  68. }
  69.  
  70. position LiFirst(List L)
  71. {
  72. return L;
  73. }
  74.  
  75. position LiNext(position p, List L)
  76. {
  77. if (p->next == NULL)
  78. exit(102);
  79. return (p->next);
  80. }
  81.  
  82. position LiPrevious(position p, List L)
  83. {
  84. position q;
  85. for (q = L; q->next != p; q = q->next);
  86. return q;
  87. }
  88.  
  89. elementtype LiRetrieve(position p, List L)
  90. {
  91. return p->next->element;
  92. }
  93.  
  94. void LiPrint(List L)
  95. {
  96. printf("\n");
  97. position p = LiFirst(L);
  98.  
  99. while (p != LiEnd(L))
  100. {
  101. printf("%c ", LiRetrieve(p, L));
  102. p = LiNext(p, L);
  103. }
  104. printf("\n");
  105. }
  106.  
  107.  
  108.  
  109. int main(void){
  110. int brojlista;
  111. int i;
  112. char c;
  113. List L[10]; /* polje od 10 List */
  114. List L1;
  115.  
  116. printf("Broj lista:\n");
  117. scanf("%d",&brojlista);
  118.  
  119. for(i=0;i<brojlista; i++)
  120. {
  121. LiMakeNull(&L1);
  122. L[i]=L1;
  123. printf("\nUpisite %d listu:\n",i+1);
  124. while(1)
  125. {
  126. scanf(" %c",&c);
  127. if ( isalpha(c)==0 ) break;
  128. LiInsert(c,LiEnd(L1),&L1);
  129. }
  130. }
  131.  
  132.  
  133. for(i=0;i<brojlista;i++)
  134. {
  135. printf("\n Lista %d izgleda ovako:", i);
  136. L1=L[i];
  137. LiPrint(L1);
  138. }
  139. return 0;
  140.  
  141. }
Advertisement
Add Comment
Please, Sign In to add comment