1. 写一个函数,实现对已经排序的主链表按顺序插入一个节点,同时更新次链表。
2. 写一个函数,给出学号,实现把指定节点从主链表中删除,同时更新次链表。如果满足条件的节点不存在则报告不存在。
3. 写一个函数,实现查询。给出学号,从主链表中找到满足条件的主节点。打印此节点的学号和成绩。给出成绩,从次链表中找到满足条件的次节点,打印此节点(可能有多个)对应的主节点的学号和成绩。如果满足条件的节点不存在则报告不存在。
4. 写一个函数,输出主链表(打印每个节点的学号和成绩)。要求提供选择,可以按学号升序输出(直接输出主链表),也可以按成绩升序输出(顺序访问次链表)
l 程序框架如下:
#include <stdlib.h>
#define NULL 0
#define LENN sizeof(struct node)
#define LENP sizeof(struct point)
struct node{int num; int grade; struct node* next;};
/* main key num is unique, but different num may have the same grade */
struct point{struct node* p; struct point* next;};
int N; /* no. of nodes */
struct point *headp;
struct node *head;
struct point* newpoint(struct node *p)
{struct point *pp=NULL;
pp=(struct point*)malloc(LENP);
if (pp==NULL) { printf("\n fail to create point\n"); exit(-1);}
else pp->p = p;
return pp;
}
struct node* newnode(int num, int grade)
{struct node *p=NULL;
p=(struct node*)malloc(LENN);
if (p==NULL)
{ printf("\n fail to create node with num=%d and grade=%d\n",num,grade);
exit(-1); }
else {p->num=num; p->grade=grade;}
return p;
}
void print(int mode)
/* mode = 0(by num) or 1(by grade) */
{…}
void insert(struct node *p)
{…}
void
{…}
void query(int mode, int val)
/* mode=0 means val is a num, mode=1 means val is a grade */
{…}
main()
{struct node *p;
int i;
N=0;
head=NULL;
headp=NULL;
for (i=1;i<4;i++)
{p=newnode(i,100-i); insert(p); }
print(0);
insert(newnode(11,99));
print(1);
query(0,23);
query(1,99);
del(1);
print(1);
点做啊?