首页 > 基础知识 > 正文

js 链表,采用链表来表示一个带符号的超长整数(20位以上)。并且进行如下处理。 将超长整数s上为奇数的数和

2020-04-20 13:19:57  来源:http://www.yummyboobs.net  编辑:admin

采用链表来表示一个带符号的超长整数(20位以上)。并且进行如下处理。 将超长整数s上为奇数的数和

思路如下,代码来自己写,就是链表的定义和基本操作链表的项存什么。因为要取出某位上源的数,所以每项存一个数即可-1345 用链表就表示为 -1 --> 1 --> 3 --> 4 --> 5遍历链表,碰到偶数就挪到链表尾部遍历链表,把结果写入文件zhidao number.txt

js数据结构中双向链表能不能插入数组?

这样?创建一个新的insert方法function insert(array){ for(var i=0;i<array.length;i++){ xxx.insert(array[i]);}}var array=[1,2,3];//这里获取到数组值insert(array);//传进zd去

数据结构课的作业 要求用链表实现学生的学号 姓名 两门课的成绩 同时求出课程的平均成绩

这是代码,还有文件#include<stdio.h>#include<stdlib.h>#include<string.h>#define LEN sizeof(struct student)void destroy(struct student* phead);void print(struct student *pstudent);struct student{char number[11];char name[10];char sex[5];int Cscore;int Jscore;int Escore; struct student *next; }; void main(){struct student *ptemp,*pstudent,*p,*padd,*pbad,*pp;FILE *pf1,*pf2;pf1 = fopen("stulist.txt", "r");if(pf1 == NULL){e799bee5baa6e997aee7ad94e78988e69d8331333330333036printf("failed to open file!");return;} pstudent= NULL; while(!feof(pf1)){ptemp = (struct student*)malloc(LEN);fscanf(pf1,"%s%s%s%d%d%d",ptemp->number, ptemp->name, ptemp->sex, &ptemp->Cscore, &ptemp->Jscore, &ptemp->Escore); ptemp->next = NULL;if(pstudent== NULL)pstudent = ptemp; else{ptemp->next = pstudent; pstudent = ptemp;}}fclose(pf1);ptemp=pstudent; while(ptemp!=NULL){if((ptemp->Cscore+ptemp->Jscore+ptemp->Escore)/3>80)printf("%s\t%s\t%d\n",ptemp->name,ptemp->number,(ptemp->Cscore+ptemp->Jscore+ptemp->Escore)/3);ptemp=ptemp->next;}p=ptemp;ptemp=pstudent;pf2 = fopen("studentadd.txt", "r");if(pf2 == NULL){printf("failed to open file!");return;} while(!feof(pf2)){padd = (struct student*)malloc(LEN);fscanf(pf2, "%s%s%s%d%d%d",padd->number, padd->name, padd->sex, &padd->Cscore, &padd->Jscore, &padd->Escore);}printf("\n"); while(strcmp(padd->number,ptemp->number)>0) { p=ptemp; ptemp=ptemp->next; } if(strcmp(padd->number,ptemp->number)<=0) { p->next=padd; padd->next=ptemp; }pbad=pstudent; pp=pstudent; while(pbad->Jscore>=70) { pp=pbad; pbad=pbad->next; } if(pbad->Jscore<70) pp->next=pbad->next; print(pstudent); destroy(pstudent);}void destroy(struct student* phead){struct student *ptemp;while(phead != NULL){ptemp = phead;phead = phead->next;free(ptemp);}}void print(struct student *pstudent){while(pstudent!=NULL){printf("%s\t%s\t%s\t%d\t%d\t%d",pstudent->number, pstudent->name, pstudent->sex, pstudent->Cscore, pstudent->Jscore, pstudent->Escore);printf("\n");pstudent=pstudent->next;}}文件 新建一个txt文档,命名stulist.txt0764181057林婷婷女8790780764181058刘俊伟男9965560764181060卢京京女809096再建一个文档,命名studentadd.txt,0764181059戴国锋男819289就可以运行1. 创建一个复杂数据(结构体)类型,该类型的变量能够存放一个学生的信息,包括:学号、姓名、性别以及三门课程的成绩(C程序设计、计算机科学导论和大学英语),要求性别用中文“男/女”表示。2. 新建链表存放以下三个学生的信息(链表的每一个节点存放一个学生的信息,各节点以学号递增的顺序排列):0764181057林婷婷女8790780764181058刘俊伟男9965560764181060卢京京女8090963. 列出平均分高于80分的学生姓名,学号和平均成绩,如:林婷婷 0764181057 85.04. 向链表中插入一个学生,插入完成后链表保持学号递增顺序不变,该生信息为:0764181059戴国锋男8192895. 从链表中删除“计算机科学导论”课程成绩低于70分的学生。6.编写一个遍历输出该链表全体数据的函数,并在新建、插入、删除等操作后调用以验证程序的正确性。这是实现的功能

求教c语言大神,本呆萌欲建两链表list1&list2,长度len1&len2,代码下面,不知哪有问题了?

排版这么差的代码真是不想看。你有两个判断相等的地方都用了赋值等号=,应该用判断等号==,改过来。

把一个单链表奇偶性拆成两个链表,原链表不变。

# include<stdio.h># include<stdlib.h># define SIZE sizeof(struct student )struct student {int data;struct student * next;};struct student * creatlist(){struct student * head;struct student * p1;struct student * p2;head = (struct student *)malloc(SIZE);head->next = NULL;p2 = head;p1 = (struct student *)malloc(SIZE);scanf("%d",&p1->data);while(p1->data!=0){e799bee5baa6e997aee7ad94e4b893e5b19e31333264656138p1->next = p2->next;p2->next = p1;p2 = p2->next;p1 = (struct student *)malloc(SIZE);scanf("%d",&p1->data);}p2->next = NULL;free(p1);return head;}struct student *creatlistjs(struct student * mhead){struct student * head;struct student * p1;struct student * p2;struct student * p3;struct student * p4;head =(struct student *)malloc(SIZE);head->next = NULL;p1 =(struct student *)malloc(SIZE);p4 = head;p3 = mhead;p2 = mhead->next ;while(p2!=NULL){p1 = p3;p1->next = p4->next ;p4->next = p1;p4 = p4->next ;p3 = p3->next ;p3 = p3->next ;p2 = p2->next ;p2 = p2->next ;}p4->next = NULL;free(p1);return head;}struct student * creatlistos(struct student *mhead){struct student * head;struct student * p1;struct student * p2;struct student * p3;struct student * p4;head =(struct student *)malloc(SIZE);head->next = NULL;p1 =(struct student *)malloc(SIZE);p4 = head;p3 = mhead;p2 = mhead->next ;while(p2!=NULL){p1 = p2;p1->next = p4->next ;p4->next = p1;p4 = p4->next ;p3 = p3->next ;p3 = p3->next ;p2 = p2->next ;p2 = p2->next ;}p4->next = NULL;free(p1);return head;}void printlist(struct student *head){struct student * phead;phead = head->next;while(phead){printf("%4d",phead->data);phead = phead->next;}}main(){struct student * mhead;struct student * jshead;struct student * oshead;mhead = creatlist();printlist(mhead);jshead = creatlistjs(mhead);printlist(jshead);oshead = creatlistos(mhead);printlist(oshead);}大体思路对了,具体的实现还有点问题,楼主可以自己改改