帮改一下C语言单项链表(有代码)

来源:百度知道 编辑:UC知道 时间:2024/06/04 01:11:51
1.调试时候总提示是Print()函数中的*p有问题,不能打印。
2.如果这段程序要改成表尾插入新节点要怎么改
谢谢~(我会多给点积分值,这小段代码都疯了我一晚上了)
#include<stdio.h>
#include<stdlib.h>

//进程控制块
typedef struct process
{
char pname[10];
int start_time;
int running_time;
struct process *next;
}Process;

//进程初始化
int num;
//int total=0;
void Initlist(Process *head_new)
{
head_new=(Process *)malloc(sizeof(struct process));
head_new->next=NULL;
}
void Print(Process *head_new,int n)
{
Process *p;
p=(Process *)malloc(sizeof(struct process));
p=head_new->next;

while(p!=NULL)
{
printf("%s %d %d",p->pname,p->start_time,p->running_time);
p=p->next;
}
printf("\n");
}
void creat_process(Process*head_new,int n)
{
Process *s,*tail;
tail=(Process *)malloc(sizeof(struct process));
int i;

改掉的你的代码部分用//d注掉了

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

//进程控制块
typedef struct process
{
char pname[10];
int start_time;
int running_time;
struct process *next;
}Process;

//进程初始化
int num;
//int total=0;
//d void Initlist(Process *head_new)
//d {
//d head_new=(Process *)malloc(sizeof(struct process));
//d head_new->next=NULL;
//d }
void Print(Process *head_new,int n)
{
Process *p = head_new;
//d Process *p;
//d p=(Process *)malloc(sizeof(struct process));
//d p=head_new->next;

while(p!=NULL)
{
printf("%s %d %d\n",p->pname,p->start_time,p->running_time);
p=p->next;
}
printf("\n");
}
//d void creat_process(Process*head_new,int n)
void creat_process(Process **head_new,int n)
{
//d Process *s,*tail;
Process **s = he