Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- // types
- typedef struct Node Node;
- typedef Node * NodePointer;
- // data
- struct Node {
- int address;
- int size;
- int temp;
- NodePointer nextNode;
- };
- // functions
- int randomfunc(int a, int b) {
- return a + (rand() % (a + b + 1));
- }
- void create(NodePointer * list, int listLength) {
- NodePointer newNode = NULL;
- for (int i = 0; i < listLength; i++) {
- newNode = malloc(sizeof(Node));
- if ((*list) == NULL) {
- newNode->address = 0;
- } else {
- newNode->address = (*list)->address + (*list)->size;
- }
- newNode->size = randomfunc(5, 45);
- newNode->temp = randomfunc(5, 15);
- newNode->nextNode = *list;
- *list = newNode;
- }
- }
- void display(NodePointer * list) {
- while (*list != NULL) {
- printf("Node(address=%d, size=%d, temp=%d)\n", (*list)->address,
- (*list)->size, (*list)->temp);
- (*list) = (*list)->nextNode;
- }
- }
- int main() {
- NodePointer list = NULL;
- create(&list, 3);
- display(&list);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement