好文档 - 专业文书写作范文服务资料分享网站

[VIP专享]C语言 建立 输出 插入 删除 修改功能的单项动态链表

天下 分享 时间: 加入收藏 我要投稿 点赞

C语言链表类题目

#include #include #include

struct Student{

long num;float score;

struct Student* next;struct Student *pre;};

int n=0;

struct Student* create(void){

struct Student *head;struct Student *tail;struct Student *pre;struct Student *p;

head = NULL;

写函数一个有三名学生数据的, 有建立 输出 插入 删除 修改功能的单项动态链表,很全

面,各种测试都试过了,环境VC6.0结构体为学号 成绩

pre = NULL;

p=(struct Student*)malloc(sizeof(struct Student));printf(\请输入用户名和得分:\\n\scanf(\if (0 == p->num){

return NULL;}

while(0 != p->num){

n++;

if (NULL == head){

head=p;tail=p;

pre = NULL;

}

} else{

pre = tail;tail->next=p;tail=p;

}

if (NULL != pre){

tail->next=NULL;}

return head;

tail->next = NULL;

void print(struct Student *head){

struct Student *p=head;if (NULL == p){

printf(\该链表中还没有数据\\n\}

while (p !=NULL){

printf(\p=p->next;}}

struct Student *del(struct Student *head, long num){

struct Student *p1 = head;struct Student *p2 = head;if (NULL == head){

return NULL;}

if (NULL == head->next){

if (num == head->num){

}

p=(struct Student*)malloc(sizeof(struct Student));printf(\请输入用户名和得分:\\n\scanf(\

}

} else{

return head;

return head;

n--;

return NULL;

}

if (num == head->num){

n--;

head=head->next;return head;}

if (NULL == head->next->next){

if (num == head->next->num){

n--;

head->next = NULL;return head;}}

p1 = head->next;while (p1!=NULL){

if (num == p1->num){

n--;

if (NULL == p1->next){

p2->next = NULL;} else{

p2->next = p1->next;}}

p1 = p1->next;p2 = p2->next;}

}

return head;

while (p!=NULL){

if (num == p->num){

p->score = score;}

p = p->next;}

}

struct Student *alter(struct Student *head, long num, float score){

struct Student *p = head;

struct Student *insert(struct Student *head, long num, float score){

struct Student *p1=head;struct Student *p2=head;struct Student *p;

p=(struct Student*)malloc(sizeof(struct Student));p->num = num;p->score = score;

if (NULL == head)

{

head = p;

head->next = NULL;return head;}

if (NULL == head->next){

if (num >= head->num){

head->next = p;p->next =NULL;return head;} else{

}

}

p->next = head;head = p;return head;

}

if (num < head->num){

p->next = head;head = p;return head;}

p1=head->next;while (p1!=NULL){

if (num >= p2->num){

if (num <= p1->num){

p->next = p1;p2->next = p;} else{

if (NULL == p1->next){

p1->next = p;p->next = NULL;}}}

p1 = p1->next;p2 = p2->next;}

return head;

int main()

{

struct Student *head = create();long num_del;long num_insert;float score_insert;long num_alter;

[VIP专享]C语言 建立 输出 插入 删除 修改功能的单项动态链表

C语言链表类题目#include#include#includestructStudent{longnum;floatscore;structStudent*next;structStudent*pre;};intn=0;stru
推荐度:
点击下载文档文档为doc格式
8h5zq03evu9y6ym8c7oz9pugm7qng700f3x
领取福利

微信扫码领取福利

微信扫码分享