Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <string.h>
- #include <time.h>
- #define MAX 20
- typedef struct l
- {
- int i;
- struct l * next;
- } LIST;
- void fill(int * a);
- void lcopy(int * a, LIST * head, LIST * tail);
- void list(int * a, char * c);
- void main(int argc, char * argv[])
- {
- srand(time(NULL));
- int a[255];
- int b[255];
- int s;
- s = sizeof(LIST);
- LIST * l;
- LIST * head = NULL;
- LIST * tail = NULL;
- // Fill array with random numbers.
- fill(a);
- // Fill array with random numbers.
- fill(b);
- // Copy array to linked list.
- lcopy(a, head, tail);
- l = head;
- if(l == NULL)
- {
- printf("Empty\n");
- }
- else
- {
- while(l != NULL)
- {
- printf("%d\n", l->i);
- l=l->next;
- }
- }
- }
- void fill(int * a)
- {
- int i = 0;
- for(i=0; i<MAX; i++)
- {
- a[i] = rand() % 10000;
- }
- }
- void lcopy(int * a, LIST * head, LIST * tail)
- {
- int i = 0;
- LIST * l;
- for(i=0; i<MAX; i++)
- {
- l = malloc(sizeof(LIST));
- l->i = a[i];
- if(head == NULL)
- {
- head = l;
- tail = l;
- }
- else
- {
- tail->next = l;
- tail = l;
- }
- printf("%d\n", l->i);
- l->next = NULL;
- }
- }
- void list(int * a, char * c)
- {
- int i = 0;
- for(i=0; i<strlen(c); i++)
- {
- printf("%c", c[i]);
- }
- for(i=0; i<MAX; i++)
- {
- printf("%d\n", a[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement