Hello I have been working on a linked list program for homework.
I have to make a list of 25 random numbers in ORDERED LINKED LIST here is my code
Code:
#include<stdlib.h>
#include<stdio.h>
void inn(int);
struct node {
int val;
struct node * next;
};
typedef struct node item;
void main() {
item * cptr, * hptr;
int i,num;
hptr = NULL;
srand(time(NULL));
for(i=0;i<25;i++) {
num= rand() % 99 + 1;
cptr = (item *)malloc(sizeof(item));
cptr->val = num;
cptr->next = hptr;
hptr = cptr;
cptr = hptr;
}
while(cptr) {
printf("%d\n", cptr->val);
cptr = cptr->next ;
}
}
This produces a linked list but not in order. This topic seems very difficult or am I learning impaired I cant Imagine doing trees my branches would fall off please help!!!! P.S. Proffessor
says linked lists are fun.