Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Example program
- #include <stdio.h>
- #include <stdlib.h>
- struct NodeList
- {
- void* data;
- struct NodeList* next;
- } *head = NULL;
- void prnint(void* p) {
- printf("%c ", *(char*)p);
- }
- void createList(char a[], int n, struct NodeList** r)
- {
- struct NodeList* root;
- root = (struct NodeList*)malloc(sizeof(struct NodeList));
- void* p = malloc(sizeof(a[0]));
- *(char*)p = a[0];
- root->data = p;
- root->next = NULL;
- struct NodeList* last = root;
- for (int i = 1; i < n; i++)
- {
- struct NodeList* t = (struct NodeList*)malloc(sizeof(struct NodeList));
- last->next = t;
- void* p2 = malloc(sizeof(char));
- *(char*)p2 = a[i];
- t->data = p2;
- t->next = NULL;
- last = t;
- }
- (*r) = root;
- // prnint(head->data); // принтираме стойността помощната функция
- }
- void printList(struct NodeList** Head)
- {
- struct NodeList* p = *Head;
- while (p)
- {
- prnint(p->data);
- p = p->next;
- }
- }
- int main()
- {
- char a[] = { 'a','b','c' };
- createList(a, sizeof(a) / sizeof(a[0]), &head);
- //prnint(head->data);
- printList(&head);
- }
Add Comment
Please, Sign In to add comment