Multi Linked List Data Structures in C

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ahsan Ali
    New Member
    • Nov 2011
    • 1

    Multi Linked List Data Structures in C

    How to make a class data base using multi linked list data structures(in C)?.
    In class's Database : one column for 'Subjects' and other one for 'student's Roll Nos' . Now the task is to point 'subject' to the respective 'student'...
    I know single and double linked list ... But I have never worked with 2-D linked list.
    Please anyone help me out?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    It's the same as working with a linked list where each node is itself a linked list in it's own right. That is, you have a node pointer as the data in the node. That is your start node for the second dimension list.

    You will need one set of functions to manage a list where the nodes contain a node pointer as data as well as second set of functions to manage a list where the nodes contain a pointer to actual data.

    Comment

    • akashjiit
      New Member
      • Mar 2014
      • 2

      #3
      I am giving you the code similar to one you asked for(you will never find codes or questions on multi linked list on net! So make sure you undertand it by heart..)
      Code:
      #include<stdio.h>
      #include<conio.h>
      #include<stdlib.h>
      struct scorel
      {
      int no;
      struct scorel *rp;
      };
      struct namel
      {
      char a[10];
      struct scorel *rp;
      struct namel *dp;
      };
      void main()
      {
      int i,j,n,m;
      struct namel *temp,*head,*end,**s;
      struct scorel *tmp,*had,*nd;
      clrscr();
      printf("enter no of students");
      scanf("%d",&n);
      end=NULL;
      for(i=0;i<n;i++)
      {
      temp=(struct namel*)malloc(sizeof(struct namel));
      printf("enter name\n");
      scanf("%s",temp->a);
      temp->rp=NULL;
      temp->dp=NULL;
      *(s+i)=temp;
      if(end==NULL)
      {
      end=head=temp;
      }
      else
      {
      end->dp=temp;
      end=temp;
      }
      printf("enter no of scores");
      scanf("%d",&m);
      nd=NULL;
      for(j=0;j<m;j++)
      {
      tmp=(struct scorel*)malloc(sizeof(struct scorel));
      printf("enter score\n");
      scanf("%d",&tmp->no);
      tmp->rp=NULL;
      if(nd==NULL)
      {
      nd=had=tmp;
      temp->rp=tmp;
      }
      else
      {
      nd->rp=tmp;
      nd=tmp;
      }
      }
      }
      for(i=0;i<n;i++)
      {
      temp=*(s+i);
      printf("%s-->",temp->a);
      tmp=temp->rp;
      while(tmp!=NULL)
      {
      printf("%d-->",tmp->no);
      tmp=tmp->rp;
      }
      printf("\n");
      }
      getch();
      }
      Last edited by Rabbit; Mar 9 '14, 11:46 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.

      Comment

      Working...