Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- #include<ctype.h>
- #define elementtype char
- #define labeltype char
- #define LAMBDA NULL
- typedef struct celltag1
- {
- elementtype element;
- struct celltag1 *next;
- } celltype1;
- typedef struct _cell
- {
- labeltype label;
- struct _cell *leftchild, *rightchild;
- } celltype;
- typedef celltype1 *List;
- typedef celltype1 *position;
- position LiEnd(List L)
- {
- position q;
- q = L;
- while (q->next != NULL)
- q = q->next;
- return q;
- }
- int jesuma(int n)
- {
- int i=2; int k=2;
- for(i=2;i<n;k=2*k){
- i=i+k;
- }
- if(i==n)return 1;
- else return 0;
- }
- position LiMakeNull(List *Lp)
- {
- *Lp = (celltype1*)malloc(sizeof(celltype1));
- (*Lp)->next = NULL;
- return (*Lp);
- }
- void LiInsert(elementtype x, position p, List *Lp)
- {
- position temp;
- temp = p->next;
- p->next = (celltype1*)malloc(sizeof(celltype1));
- p->next->element = x;
- p->next->next = temp;
- }
- void LiDelete(position p, List *Lp)
- {
- position temp;
- temp = p->next;
- p->next = p->next->next;
- free(temp);
- }
- position LiFirst(List L)
- {
- return L;
- }
- position LiNext(position p, List L)
- {
- if (p->next == NULL)
- exit(102);
- return (p->next);
- }
- position LiPrevious(position p, List L)
- {
- position q;
- for (q = L; q->next != p; q = q->next);
- return q;
- }
- elementtype LiRetrieve(position p, List L)
- {
- return p->next->element;
- }
- void LiPrint(List L)
- {
- printf("\n");
- position p = LiFirst(L);
- while (p != LiEnd(L))
- {
- printf("%c ", LiRetrieve(p, L));
- p = LiNext(p, L);
- }
- printf("\n");
- }
- int main(void){
- int brojlista;
- int i;
- char c;
- List L[10]; /* polje od 10 List */
- List L1;
- printf("Broj lista:\n");
- scanf("%d",&brojlista);
- for(i=0;i<brojlista; i++)
- {
- LiMakeNull(&L1);
- L[i]=L1;
- printf("\nUpisite %d listu:\n",i+1);
- while(1)
- {
- scanf(" %c",&c);
- if ( isalpha(c)==0 ) break;
- LiInsert(c,LiEnd(L1),&L1);
- }
- }
- for(i=0;i<brojlista;i++)
- {
- printf("\n Lista %d izgleda ovako:", i);
- L1=L[i];
- LiPrint(L1);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment