Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct listelem
- {
- int data;
- struct listlem *next;
- }listelem;
- beszurElore(listelem *list, int data)
- {
- listelem *uj = (listelem*)malloc(sizeof(listelem));
- uj->next = list;
- uj->data = data;
- list = uj;
- }
- kiir(listelem *list)
- {
- while (list != NULL)
- {
- printf("%p %d\n", list, list->data);
- list = list->next;
- }
- }
- int pozitiv(listelem * list)
- {
- int p = 0;
- while (list != NULL)
- {
- if (list->data > 0)
- {
- p++;
- }
- list = list->next;
- }
- return p;
- }
- int main()
- {
- listelem *list1 = NULL;
- for (int i = 0; i < 20; i++)
- {
- list1 = beszurElore(list1, (rand()-16383) % 100);
- }
- kiir(list1);
- printf("A listaban %d pozitiv elem van", pozitiv(list1));
- return 0;
- }
Add Comment
Please, Sign In to add comment