C programming Given a linked list of 20 random numbers from

C programming

Given a linked list of 20 random numbers from 0 to 30. Run a FIFO(First in First out) algorithm on the list of random numbers.

Solution

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

struct node{
   int value;
   struct node* next;
};

void FIFO( struct node* LL ){
   while( LL ){
       printf(\"Popping out: %d\ \", (int)(LL->value) );
       struct node* temp = (struct node*)(LL->next);
       free( LL );
       LL = temp;
   }
}

int main(){
   srand(time(NULL));
   struct node* linkedlist = (struct node*)malloc( sizeof( struct node) );
   linkedlist->value = rand()%31;
   struct node* ll = linkedlist;
   int i = 1;
   for(; i < 20; i++){
       ll->next = (struct node*)malloc( sizeof(struct node) );
       ll = ll->next;
       ll->value = rand()%31;
   }
   ll->next= NULL;

   ll = linkedlist;
   printf(\"Linked list is: \");
   while( ll ){
       printf( \"%d \", (ll->value));
       ll =ll->next;
   }
   printf(\"\ \");

   FIFO(linkedlist);


}

C programming Given a linked list of 20 random numbers from 0 to 30. Run a FIFO(First in First out) algorithm on the list of random numbers.Solution#include <

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site