Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.24 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. struct list
  5. {
  6.     int value;
  7.     struct list *next;
  8. };
  9.  
  10. void enterList(struct list **first, struct list **last){
  11.     printf("Введите количество элементов:");
  12.     int count=0;
  13.     int tek;
  14.     int i;
  15.     scanf("%u",&count);
  16.     for(i=0; i<count;i++)
  17.     {
  18.         printf("Число %d:\n",i+1);
  19.         scanf("%d",&tek);
  20.         sls_store(tek,&first,&last);
  21.     }
  22.     display(first);
  23. }
  24.  
  25. void display(struct list *p)
  26. {
  27.   while(p!=NULL) {
  28.     printf("%d\n", p->value);
  29.     p = p->next;
  30.   }
  31. }
  32.  
  33. void sls_store(int num,struct list **first)
  34. {
  35.     struct list *localPTR = *first;
  36.     if(*first == NULL){
  37.             first = malloc(sizeof(struct list));
  38.             (*first)->value = num;
  39.             (*first)->next = NULL;
  40.     }else{
  41.             localPTR = *first;
  42.             while(localPTR->next != NULL){
  43.                     localPTR = localPTR->next;
  44.             };
  45.             localPTR->next = malloc(sizeof(struct list));
  46.             localPTR = localPTR->next;
  47.             localPTR->value = num;
  48.             localPTR->next = NULL;
  49.     };
  50. }
  51.  
  52. int main(void)
  53. {
  54.     struct list *first=NULL;
  55.     struct list *last=NULL;
  56.     enterList(&first, &last);
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement