Skip to content

Commit

Permalink
Update Fitness.c
Browse files Browse the repository at this point in the history
  • Loading branch information
arnav108276 authored Sep 26, 2024
1 parent 07d3c20 commit cec0064
Showing 1 changed file with 0 additions and 58 deletions.
58 changes: 0 additions & 58 deletions Fitness.c
Original file line number Diff line number Diff line change
@@ -1,59 +1 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

typedef struct node {
int data;
struct node* east;
struct node* west;
struct node* north;
} Node;

Node* createNode(int data) {
Node* newNode = (Node*) malloc(sizeof(Node));
newNode->data = data;
newNode->east = newNode->west = newNode->north = NULL;
return newNode;
}

// Function to dynamically fill the linked list with random data
void fillLinkedList(Node** head, int size, int min, int max) {
srand(time(NULL)); // seed random number generator
Node* current = *head;
for (int i = 0; i < size; i++) {
int data = min + rand() % (max - min + 1);
Node* newNode = createNode(data);
if (current == NULL) {
*head = newNode;
current = *head;
} else {
current->east = newNode;
current = current->east;
}
}
}

// Function to print the linked list
void printLinkedList(Node* head) {
Node* current = head;
while (current != NULL) {
printf("%d---> ", current->data);
current = current->east;
}
printf("NULL\n");
}

int main() {
int size, min, max;
printf("Enter the number of data items to generate: ");
scanf("%d", &size);
printf("Enter the minimum value of the range: ");
scanf("%d", &min);
printf("Enter the maximum value of the range: ");
scanf("%d", &max);

Node* head = NULL;
fillLinkedList(&head, size, min, max); // fill the linked list with random nodes within the specified range
printLinkedList(head); // print the linked list
return 0;
}

0 comments on commit cec0064

Please sign in to comment.