void create_e(struct department **,char *);
void create(struct department **s,char *str)
{ struct department *temp,*e;
temp=(struct department *)malloc(sizeof(struct department));
temp->dname=str;
temp->dep=NULL;
temp->emp=NULL;
if(*s==NULL)
{
*s=temp;
e=temp;
create_e(&e,temp->dname);
}
else
{
e->dep=temp;
e=temp;
create_e(&e,temp->dname);
}
}
void create_e(struct department **s,char *str)
{int x,i;
printf("enter the employee details of %s \n",str);
printf("enter the no of employee:");
scanf("%d",&x);
for(i=0;i<x;i++)
{
struct employee *temp1,*e1;
temp1=(struct employee *)malloc(sizeof(struct employee));
char *name;
printf("enter emp name:");
scanf("%s",name);
temp1->ename=name;
int age,salary;
printf("enter age:");
scanf("%d",&age);
printf("enter salary:");
scanf("%d",&salary);
temp1->age=age;
temp1->salary=salary;
temp1->next=NULL;
if((*s)->emp==NULL)
{
(*s)->emp=temp1;
e1=temp1;
}
else
{
e1->next=temp1;
e1=temp1;
}
}
}
Это программа для связанного списка в связанном list.First списке отдел, структура которогосвязанный список не дает желаемых результатов
struct department
{
char *dname;
struct department *dep;
struct employee *emp;
}
второй сотрудников с их именами, возрастом и зарплаты
struct employee
{
char *ename;
int age;
int salary;
struct employee *next;
};
мой вопрос был для отображения связанного lists.Everything дисплеев просто отлично для сотрудников names.The имени последнего сотрудника из последнего отдела, за исключением отображается на месте все другой службы ees name. Функция отображения в порядке, я попробовал ее с другими программами. Например, вывод должен быть:
maths->john|23|20->ron|24|25
sci->harry|19|8->chris|21|40
но выход выходит быть:
maths->chris|23|20->chris|24|25
sci->chris|19|8->chris|21|40
'e-> dep = temp;': 'e' неинициализирован. – BLUEPIXY
@Ali На каком краю списка вы пытаетесь вставить новые элементы? –
как горизонтальный, так и вертикальный – Ali