Hello!
I am trying hard to follow the Linked List concept.
I was trying to work towards the adjacent list. I am using the function to make adjacent list but am not able to pass my data to it.
Can someone help me with this?
the code is
Code:
struct adj_node  /*the NODE which forms the part of the adjacency list; look at figure [B]*/
{
char vertex_val;
struct adj_node *adj_next; /*red pointer*/
};

struct node /*the NODE which forms the part of the Graph; look at figure [A]*/
{
char vertex_val;
struct adj_node *down;
struct node *next;  /*black pointer*/
};

struct node *graph; 
struct node *cur_vertex, *aux_ptr;
struct adj_node *adj_cur, *new;

LinkListrepresentation()
{


/*Step-1 of the algorithm is expected from you or refer linked LISTS*/ 
/*Step-1 gives you a list, being pointed by 'graph' */ 

cur_vertex = graph;   /*first node of the graph in consideration*/
/*Step-2 starts here*/
while ( cur_vertex != NULL)
      {
       aux_ptr = graph; /*an auxiliary pointer to the graph*/
       adj_cur = NULL; /*an auxiliary pointer to keep track of the adjacency lists*/
       cur_vertex->down = adj_cur; 
       while (aux_ptr != NULL)
             {
              printf("Is there any edge between %c and %c ",aux_ptr->vertex_val, cur_vertex->vertex_val);
              scanf("%d", &edge);/*step-2: part-A*/
              if( edge == 1) /*step-2: part - B*/
                 if( adj_cur == NULL)
                   {
                    adj_cur = (struct adj_node *)malloc(sizeof(adj_node));
                    adj_cur ->vertex_val = aux_ptr->vertex_val;
                    adj_cur -> adj_next = NULL;
                   } 
                  else
                   {
                     new = (struct adj_node *)malloc(sizeof(adj_node));
                     new -> vertex_val = aux_ptr ->vertex_val;
                     adj_cur ->adj_next = new;
                     adj_cur = new; 
                     adj_cur ->adj_next = NULL;
                   }  
               aux_ptr = aux_ptr ->next;
             }
        cur_vertex = cur_vertex ->next;
     }
}
I want to pass the data to the above function for making the LL but i dont know how it shd be passed.
I am reading the data from the file as
Code:
FILE *fp;
  int i, count = 0;
  char c;
  
  fp = fopen("data","r");    // reading the Edge file
  while((c=getc(fp))!=EOF) 
    {
      if(c=='\n')
	count++;
    }
  printf("\tThe total number of entries: %d\n", count);   
  C1 = (int*) calloc(edges, sizeof(int));
  C2 = (int*) calloc(edges, sizeof(int));
  C3 = (float*) calloc(edges, sizeof(float));
  rewind(fp2);
  for (i=0;i<edges;i++)
    {
      fscanf(fp,"%d  %d %f \n", &C1[i], &C2[i], &C3[i]);
      //   printf("%d  %d %f  %c\n", C1[i], C2[i], pC3[i], C4[i]);   
      
	}