两个链表的连接问题 c高手请进
已有a,b两个链表,每个链表中的结点包括学号,成绩。要求把两个链表合并,按学号升序排列
连接函数有问题 请高手指点
#include <stdio.h>
#include <stdlib.h>
struct student{
int number;
int score;
struct student * next;
};
struct student * creat(){
int number;
int score;
struct student *head = NULL;
struct student *q = NULL;
struct student *p = NULL;
p = (struct student *)malloc(sizeof(struct student));
scanf("%d,%d",&number,&score);
while(number != NULL){
p->number = number;
p->score = score;
p->next = NULL;
if(head == NULL)
head = q = p;
else{
q->next = p;
q = p;
}
p = (struct student *)malloc(sizeof(struct student));
scanf("%d,%d",&number,&score);
}
p->next = NULL;
return head;
}
struct student * insert(struct student * ah,struct student * bh){
struct student * pa1, *pa2;
struct student * pb1, *pb2;
pa1 = pa2 = ah;
pb1 = pb2 = bh;
do{
while((pb2->number > pb1->number) && (pb1->next != NULL)){
pa2 = pa1;
pa1 = pa1->next;
}
pb2 = pb2->next;
pb1->next = pa1;
pa2->next = pb2;
pa2 = pa2->next;
pb2 = pb1
相关问答:
#include <string.h>
#include <stdio.h>
void main()
{
int i;
char buf[]="abcde";
strncpy(buf,"abc",3);
for(i=0;i <5;i++)
printf(&q ......
struct s1 {
char ch, *ptr;
union {
short a, b;
unsigned int c:2, d:1;
}
struct s1 *next;
};
主要看不懂符号 :
请达人指点一二
http://blog.cechina.cn/true ......
C/C++ 2009-9专家榜
名次 专家名称 专家分 个人描述
1 mstlq (面色铁路桥) 5843 因为菜,所以努力学习中
2 whg01 (及时结贴是美德)&n ......
比如:
char c[] = "hello,world";
char *c = "hello,world";
在分配内存时是不一样的吧?(分配到堆还是栈什么的)
谁能给讲讲C中内存是怎么分配的啊?
或者给提供个链接
......
下面是我的代码 从内存写入文件正确 但从文件读入内存都是乱码 而且程序崩溃 请c高手指点
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct inf
{
& ......