Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- struct list
- {
- int value;
- struct list *next;
- };
- void enterList(struct list **first, struct list **last){
- printf("Введите количество элементов:");
- int count=0;
- int tek;
- int i;
- scanf("%u",&count);
- for(i=0; i<count;i++)
- {
- printf("Число %d:\n",i+1);
- scanf("%d",&tek);
- sls_store(tek,&first,&last);
- }
- display(first);
- }
- void display(struct list *p)
- {
- while(p!=NULL) {
- printf("%d\n", p->value);
- p = p->next;
- }
- }
- void sls_store(int num,struct list **first)
- {
- struct list *localPTR = *first;
- if(*first == NULL){
- first = malloc(sizeof(struct list));
- (*first)->value = num;
- (*first)->next = NULL;
- }else{
- localPTR = *first;
- while(localPTR->next != NULL){
- localPTR = localPTR->next;
- };
- localPTR->next = malloc(sizeof(struct list));
- localPTR = localPTR->next;
- localPTR->value = num;
- localPTR->next = NULL;
- };
- }
- int main(void)
- {
- struct list *first=NULL;
- struct list *last=NULL;
- enterList(&first, &last);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement