c - Add nodes in a random position of a new list -


i'm facing how add nodes of single linked list in random position(without repetition of random numbers) of new list. thinking how can it. firstly, created array want save old numbers, can control if random number generated. secondly,the next step want do, add first node of old list in random position, sliding new list(empty). don't have idea how can it... how can slide old list, without ruin old list?

node * generatenewlist(node*list,int size)     {          int array[size];         node*auxlist=null;         auxlist=(node*)malloc(sizeof(node)*(size));         int cont,a;         int i,j;         for(i=0;i<size;i++)         {             cont=0;             a=rand()%size;             array[i]=a;             for(j=0;j<size;j++)             {                 if(array[j]==a)                 {                     a=rand()%size;                 }                 while(cont!=a)                 {                     cont++;                     auxlist=auxlist->next;                 }                 auxlist->data=auxlist->data;                 list=list->next;             }         }         return auxlist;     } 

these struct used create list

typedef struct {     char info[50];     type value; }data;  typedef struct {     data data;     struct node*next; }node; 


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -