C高级第三次作业(1)

6-1 输出月份英文名





1.设计思路

(1)算法:

第一步:定义整型变量n,字符指针s,输入一个数赋给n。

第二步:调用函数getmonth将值赋给s。

第三步:在函数getmonth中使用switch—case语句来实现,返回月份的英文名。

第四步:在主函数中如果s==NULL就输出wrong input,否则输出s。

(2)流程图:

2.实验代码:

  1. char *getmonth( int n ){
  2. char *a;
  3. switch(n){
  4. case 1:strcpy(a,"January");break;
  5. case 2:strcpy(a,"February");break;
  6. case 3:strcpy(a,"March");break;
  7. case 4:strcpy(a,"April");break;
  8. case 5:strcpy(a,"May");break;
  9. case 6:strcpy(a,"June");break;
  10. case 7:strcpy(a,"July");break;
  11. case 8:strcpy(a,"August");break;
  12. case 9:strcpy(a,"September");break;
  13. case 10:strcpy(a,"October");break;
  14. case 11:strcpy(a,"November");break;
  15. case 12:strcpy(a,"December");break;
  16. default:strcpy(a,"NULL");
  17. }
  18. return(a);
  19. }

修改后的代码

  1. char *getmonth( int n ){
  2. switch(n){
  3. case 1:return "January";
  4. case 2:return "February";
  5. case 3:return "March";
  6. case 4:return "April";
  7. case 5:return "May";
  8. case 6:return "June";
  9. case 7:return "July";
  10. case 8:return "August";
  11. case 9:return "Septemer";
  12. case 10:return "October";
  13. case 11:return "November";
  14. case 12:return "December";
  15. default:return NULL;
  16. }
  17. }

3.本题调试过程碰到问题及解决办法:

问题1:部分正确

错误的原因:没有声明string函数库,无法调用strcpy函数。

修正方法:自己想不出来在网上搜解题思路,自己重新写。

6-2 查找星期





1.设计思路:

(1)算法:

第一步:定义整型变量i,字符数组s[MAXS],输入一个字符串赋给s。

第二步:调用函数getindex,n=getindex的返回值。

第三步:在getindex函数中,定义整型变量a=-1,i=0,字符指针数组*week[7]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"},定义字符型指向指针的指针**p=week在for循环中i为循环变量,条件为i<7,如果strcmp(s,week[i])0,就执行a=i,然后跳出这个循环,执行完for循环最后返回a。

第四步:在主函数中如果n-1,就执行wrong input!,否则就输出n的值

(2)流程图:

2.实验代码

  1. int getindex( char *s ){
  2. int a=-1,i;
  3. char *week[7]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
  4. char **p=week;
  5. for(i=0;i<7;i++){
  6. if(strcmp(s,*(p+i))==0){
  7. a=i;
  8. break;
  9. }
  10. }
  11. return a;
  12. }

3.本题调试过程碰到问题及解决办法:

6-3 计算最长的字符串长度





1.设计思路:

(1)算法:

第一步:常量MAXN 10,MAXS 20,定义整型变量i,n,字符指针数组string[MAXN] = {NULL},输入一个数赋给n。

第二步:借助for循环i=0;条件为i<n;在for循环中动态分配内存大小为20字节,输入一个字符串赋给string[i]。

第三步:调用max_len函数,将函数max_len的返回值输出。

第四步:在函数max_len中,定义整型变量i,count=0,j,整型数组q[20]={0};借助for循环求出
(*(s+i))中的字符串的长度,将值赋给q[i];

第五步:count=q[0],借助for循环找到q[i]的最大值赋给count,最后返回count的值。

(2)流程图

2.实验代码:

  1. int max_len( char *s[], int n ){
  2. int i,count=0,j,q[20]={0};
  3. for(i=0;i<n;i++){
  4. for(j=0;*(*(s+i)+j)!='\0';j++){
  5. }
  6. q[i]=j;
  7. }
  8. count=q[0];
  9. for(i=0;i<n;i++){
  10. if(q[i]>count){
  11. count=q[i];
  12. }
  13. }
  14. return count;
  15. }

3.本题调试过程碰到问题及解决办法:

6-4 指定位置输出字符串

1.设计思路

(1)算法:

第一步:定义字符数组str[10],字符变量ch_start, ch_end,字符型指针变量p,

第二步:独树一格字符串给str,读入两个字符分别赋给ch_start, ch_end,

第三步:调用函数match,将函数的返回值赋给p。

第四步:在函数match中定义整型变量i,j,字符型指针
q=NULL,i=0,借助for循环条件为(s+i)!='\0',在for循环中如果(s+i)==ch1,定义字符型指针a=&s[i],j=i,借助for循环条件为((s+j)!=ch2)&&((s+j)!='\0'),输出字符(s+j),执行完第二个for循环判断如果(s+j)!='\0',就输出字符(s+j),并且换行,返回a的地址,执行完第一个for循环直到条件不满足,就换行并且返回q的地址。

第五步:输出字符串p。

(2)流程图:

2.实验代码:

  1. char *match( char *s, char ch1, char ch2 ){
  2. int i,j;
  3. char *q=s;
  4. for(i=0;*(s+i)!='\0';i++){
  5. if(*(s+i)==ch1){
  6. for(j=i;*(s+j)!=ch2;j++){
  7. *(q)=*(s+j);
  8. q++;
  9. }
  10. *q=ch2;
  11. }
  12. }
  13. *q='\0';
  14. printf("%s\n",q);
  15. }



修改后的代码:

  1. char *match( char *s, char ch1, char ch2 ){
  2. int i,j;
  3. char *q=NULL;
  4. for(i=0;*(s+i)!='\0';i++){
  5. if(*(s+i)==ch1){
  6. char *a= &s[i];
  7. for(j=i;(*(s+j)!=ch2)&&(*(s+j)!='\0');j++){
  8. printf("%c",*(s+j));
  9. }
  10. if(*(s+j)!='\0')
  11. printf("%c",*(s+j));
  12. printf("\n");
  13. return a;
  14. }
  15. }
  16. printf("\n");
  17. return q;
  18. }



在修改后的代码:

  1. char *match( char *s, char ch1, char ch2 ){
  2. int i,j;
  3. char *q=NULL;
  4. for(i=0;*(s+i)!='\0';i++){
  5. if(*(s+i)==ch1){
  6. char *a= &s[i];
  7. for(j=i;(*(s+j)!=ch2)&&(*(s+j)!='\0');j++){
  8. printf("%c",*(s+j));
  9. }
  10. if(*(s+j)!='\0')
  11. printf("%c",*(s+j));
  12. printf("\n");
  13. return a;
  14. }
  15. }
  16. printf("\n");
  17. return s+i;
  18. }

3.本题调试过程碰到问题及解决办法:

错误信息1:段错误

错误原因:自己没有读懂题意就写代码,一方面自己最后只是输出两个字符之间的所有字符,另一方面当函数找不到时返回得值不值空指针,代码不能满足所有的测试点。

改正方法:在一开始就定义指针为空指针,当找到的的话就重新定义一个指针,他的值为ch1的地址,输出在两个字符之间的所有字符,输出完换行并且返回指针变量,没有找到,就换行并且返回空指针。

错误信息2:部分正确有一个测试点错误

错误原因:在最后的返回值返回的是空指针原来返回的是q空指针

改正方法:将返回值改成s+i

码云代码存放:

C高级第三次作业(2)

6-1 奇数值结点链表







1.设计思路

(1)算法:

第一步:声明结构体类型,整型变量data,结构体指针变量next

第二步:在主函数中,定义结构体指针变量
L,Odd,调用函数readlist将函数的返回值给L,调用函数getodd,将函数的返回值给Odd,

第三步:在readlist函数中,定义结构体指针变量
head=NULL,p=NULL,q=NULL,整型数data,对p,q动态分配内存类型强制转化为结构体指针,大小为sizeof(struct ListNode),读入一个书给p->data,使用while语句条件为p->data!=-1,在循环语句中如果headNULL,head=p,否则q->next=p,在if语句结束之后q=p,在对p动态分配内存类型强制转化为结构体指针,大小为sizeof(struct ListNode),读入一个数给p->data,在执行完while语句后q->next=NULL,返回head。

第四步:在getodd函数中,定义结构体指针变量head=NULL,q=NULL,p,w=NULL,head1=NULL,如果L!=NULL就执行for循环,for循环条件1为head=*L,条件2为head!=NULL,条件3为head=head->next,在for循环中如果head->data%2!=0执行head1=head,否则执行p->next=head,在if语句之后p=head,如果head->data%2!=0不满足,就执行如果qNULL,q=head,否则w->next=head,在if语句之后执行w=head,执行完for循环后p->next=NULL,如果w!=NULL执行w->next=NULL。最后*L=q。在第一个if不满足时返回NULL,在最后返回head1.

第五步:两次调用函数printlist,将奇数和偶数的链表分别打印出来。

(2)流程图:

2.实验代码:

  1. struct ListNode *readlist(){
  2. struct ListNode *head=NULL,*p=NULL,*q=NULL;
  3. int data;
  4. p=q=(struct ListNode *)malloc(sizeof(struct ListNode));
  5. scanf("%d",&p->data);
  6. while(p->data!=-1){
  7. if(head==NULL){
  8. head=p;
  9. }else{
  10. q->next=p;
  11. }
  12. q=p;
  13. p=(struct ListNode *)malloc(sizeof(struct ListNode));
  14. scanf("%d",&p->data);
  15. }
  16. return head;
  17. }
  18. struct ListNode *getodd( struct ListNode **L ){
  19. struct ListNode *head=NULL,*q=NULL,*p,*w=NULL,*head1=NULL;
  20. if(*L!=NULL){
  21. for(head=*L;head!=NULL;head=head->next){
  22. if(head->data%2!=0){
  23. if(head1==NULL){
  24. head1=head;p=head1;
  25. }else{
  26. e->next=p;
  27. }
  28. for(q=*L;q->data%2==0&&q->next!=NULL;q=q->next){
  29. w=q;
  30. }
  31. if(q->data%2!=0){
  32. if(q=*L){
  33. *L=q->next;
  34. }else{
  35. w->next=q->next;
  36. }
  37. }//
  38. }
  39. }
  40. w->next=NULL;
  41. }else{
  42. return NULL;
  43. }
  44. e->next=NULL;
  45. return head1;
  46. }



修改后的代码:

  1. struct ListNode *readlist(){
  2. struct ListNode *head=NULL,*p=NULL,*q=NULL;
  3. int data;
  4. p=q=(struct ListNode *)malloc(sizeof(struct ListNode));
  5. scanf("%d",&p->data);
  6. while(p->data!=-1){
  7. if(head==NULL){
  8. head=p;
  9. }else{
  10. q->next=p;
  11. }
  12. q=p;
  13. p=(struct ListNode *)malloc(sizeof(struct ListNode));
  14. scanf("%d",&p->data);
  15. }
  16. q->next=NULL;
  17. return(head);
  18. }
  19. struct ListNode *getodd( struct ListNode **L ){
  20. struct ListNode *head=NULL,*q=NULL,*p,*w=NULL,*head1=NULL;
  21. if(*L!=NULL){
  22. for(head=*L;head!=NULL;head=head->next){
  23. if(head->data%2!=0){
  24. if(head1==NULL){
  25. head1=head;
  26. }else{
  27. p->next=head;
  28. }
  29. p=head;
  30. }else{
  31. if(q==NULL){
  32. q=head;w=q;
  33. }else{
  34. w->next=head;
  35. }
  36. }
  37. }
  38. p->next=NULL;
  39. if(w!=NULL)
  40. w->next=NULL;
  41. *L=q;
  42. }else{
  43. return NULL;
  44. }
  45. return(head1);
  46. }



再次修改

  1. struct ListNode *readlist(){
  2. struct ListNode *head=NULL,*p=NULL,*q=NULL;
  3. int data;
  4. p=q=(struct ListNode *)malloc(sizeof(struct ListNode));
  5. scanf("%d",&p->data);
  6. while(p->data!=-1){
  7. if(head==NULL){
  8. head=p;
  9. }else{
  10. q->next=p;
  11. }
  12. q=p;
  13. p=(struct ListNode *)malloc(sizeof(struct ListNode));
  14. scanf("%d",&p->data);
  15. }
  16. q->next=NULL;
  17. return(head);
  18. }
  19. struct ListNode *getodd( struct ListNode **L ){
  20. struct ListNode *head=NULL,*q=NULL,*p,*w=NULL,*head1=NULL;
  21. if(*L!=NULL){
  22. for(head=*L;head!=NULL;head=head->next){
  23. if(head->data%2!=0){
  24. if(head1==NULL){
  25. head1=head;
  26. }else{
  27. p->next=head;
  28. }
  29. p=head;
  30. }else{
  31. if(q==NULL){
  32. q=head;
  33. }else{
  34. w->next=head;
  35. }
  36. w=head;
  37. }
  38. }
  39. p->next=NULL;
  40. if(w!=NULL)
  41. w->next=NULL;
  42. *L=q;
  43. }else{
  44. return NULL;
  45. }
  46. return(head1);
  47. }

3.本题调试过程碰到问题及解决办法:

错误信息1:

错误的原因:调试的过程中知道1在建立链表时没将最后一个节点的值赋值为NULL。2.p的地址一直都是head1的起始地址,没有将p的地址变化

修改方法在建立链表的函数中最后加上p->next=NULL,在getodd函数中p=head。

错误信息2.

错误原因:同样的问题w的地址一直都是q的起始地址没有叫它改变,

改正方法:使w=head。

6-2 学生成绩链表处理







1.设计思路

(1)算法

第一步:声明结构体类型,整型数num,字符数组name[20],整型数score结构体指针变量next,

第二步:主函数中,定义整型min_score,结构体指针变量
p,head=NULL,调用函数creatlist,将creatlist的返回值赋给head,

第三步在creatlist函数中,定义结构体指针变量
head,p=NULL,q=NULL,对p和q动态分配内存类型强制转化为结构体指针,大小为sizeof(struct stud_node),读入一个数赋给p->num,使用while循环条件为p->num!=0,在循环体中,读入一个字符串和整型数字给p->name和p->score,如果headNULL,head=p,否则q->next=p。if语句结束执行q=p 在对p动态分配内存类型强制转化为结构体指针,大小为sizeof(struct stud_node),,读入一个数赋给p->num,当while天剑不满足时执行q->next=NULL,返回head给主函数

第四步:在主函数中输入一个数给min_score,调用函数deletelist,将函数的返回值给head,

第五步:定义结构体指针变量p,q,*w,使用if语句,条件为head!=NULL,借助for循环条件1为w=head,条件2为w!=NULL条件3为w=w->next,在循环体中借助if语句条件为w->score<min_score,借助for循环条件1为p=head条件2为min_score<=p->score&&p->next!=NULL条件3为p=p->next,在循环体中执行q=p。直到结束使用if语句条件min_score>p->score,在判断语句中使用if语句条件为phead执行head=p->next否则执行q->next=p->next,在第一个if语句不满足时返回NULL,最后返回head

第六步:打印链表head,

(2).流程图:

2.实验代码

  1. struct stud_node *createlist(){
  2. struct stud_node *head=NULL,*p=NULL,*q=NULL;
  3. p=q=(struct stud_node *)malloc(sizeof(struct stud_node));
  4. int num;
  5. char name[20];
  6. int score;
  7. scanf("%d",&p->num);
  8. while(p->num!=0){
  9. scanf("%s %d",p->name,&p->score);
  10. if(head==NULL){
  11. head=p;
  12. }else{
  13. q->next=p;
  14. }
  15. q=p;
  16. p=(struct stud_node *)malloc(sizeof(struct stud_node));
  17. scanf("%d",&p->num);
  18. }
  19. q->next=NULL;
  20. return (head);
  21. }
  22. struct stud_node *deletelist( struct stud_node *head, int min_score ){
  23. struct stud_node *p,*q,*w;
  24. int i;
  25. if(p!=NULL){
  26. for(w=head;w!=NULL;w=w->next){
  27. p=head;
  28. while(min_score<=p->score&&p->next!=NULL){
  29. q=p;p=p->next;
  30. }
  31. if(min_score>p->score){
  32. if(p==head){
  33. head=p->next;
  34. }else{
  35. q->next=p->next;
  36. }
  37. }
  38. }
  39. }
  40. return (head);
  41. }



修改后的代码

  1. struct stud_node *createlist(){
  2. struct stud_node *head=NULL,*p=NULL,*q=NULL;
  3. p=q=(struct stud_node *)malloc(sizeof(struct stud_node));
  4. scanf("%d",&p->num);
  5. while(p->num!=0){
  6. scanf("%s %d",p->name,&p->score);
  7. if(head==NULL){
  8. head=p;
  9. }else{
  10. q->next=p;
  11. }
  12. q=p;
  13. p=(struct stud_node *)malloc(sizeof(struct stud_node));
  14. scanf("%d",&p->num);
  15. }
  16. q->next=NULL;
  17. return (head);
  18. }
  19. struct stud_node *deletelist( struct stud_node *head, int min_score ){
  20. struct stud_node *p,*q,*w;
  21. if(head!=NULL){
  22. for(w=head;w!=NULL;w=w->next){
  23. if(w->score<min_score){
  24. for(p=head;min_score<=p->score&&p->next!=NULL;p=p->next){
  25. q=p;
  26. }
  27. if(min_score>p->score){
  28. if(p==head){
  29. head=p->next;
  30. }else{
  31. q->next=p->next;
  32. }
  33. }
  34. }
  35. }
  36. return (head);
  37. }
  38. else{
  39. return NULL;
  40. }
  41. }

3.本题调试过程碰到问题及解决办法:

错误信息1

错误原因:只删除一个不满足条件的节点。

改正方法,使用for循环每找到一个不满足条件的就执行一次删除操作。

6-3 链表拼接

1.设计思路:

(1)算法:自己的思路有问题;

(2)流程图

2.实验代码:

  1. struct ListNode *mergelists(struct ListNode *list1, struct ListNode *list2){
  2. struct ListNode *head,*p,*q;
  3. int a[10],i=0;
  4. for(p=list1;p!=NULL;p=p->next){
  5. a[i++]=p->data;
  6. }
  7. for(p=list2;p!=NULL;p=p->next){
  8. a[i++]=p->data;
  9. }
  10. int j,n,k,temp;
  11. n=i;
  12. for(i=0;i<n-1;i++){
  13. k=i;
  14. for(j=i;j<n;j++){
  15. if(a[j]<a[k]){
  16. j=k;
  17. }
  18. }
  19. if(k!=i){
  20. temp=a[i];a[i]=a[k];a[k]=temp;
  21. }
  22. }
  23. for(i=0;i<n;i++){
  24. p->data=a[i];
  25. if(head==NULL){
  26. head=p;
  27. }else{
  28. q->next=p;
  29. }
  30. q=p;
  31. }
  32. q->next=NULL;
  33. return head;
  34. }

3.本题调试过程碰到问题及解决办法:

错误信息1:

错误原因:考虑不全面

改正方法:不会。

博客上的题目



实验代码:

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. long *zhishu(long *p,int a,int b);
  5. void print(long *p,int a,int b);
  6. int main()
  7. {
  8. int a=201,b=3936,i,j;
  9. long n[a*b],*p;
  10. for(i=0;i<a;i++){
  11. for(j=0;j<b;j++){
  12. n[(i+1)*(j+1)]=(i+1)*(j+1);
  13. }
  14. }
  15. p=zhishu(n,a,b);
  16. print(p,a,b);
  17. return 0;
  18. }
  19. long *zhishu(long *p,int a,int b){
  20. int i,j,c=2,d=0;
  21. long *q=p;
  22. j=a*b;
  23. for(i=0;i<j&&c<=sqrt(a*b);i++){
  24. d=0;
  25. if(*(q+i)!=1){
  26. if(*(q+i)%c!=0){
  27. q[d++]=*(q+i);
  28. }
  29. }
  30. j=d;
  31. c=q[0];
  32. }
  33. return q;
  34. }
  35. void print(long *p,int a,int b){
  36. int i;
  37. for(i=0;*(p+i)<=a*b;i++){
  38. if((i+1)%5!=0){
  39. printf("%ld ",*(p+i));
  40. }else{
  41. printf("%ld\n",*(p+i));
  42. }
  43. }
  44. }

运行出错,不会写

修改后的代码:

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define N 20
  4. #define M 39
  5. void delete(int s[N][M],int x);
  6. int main()
  7. {
  8. int i,j,a[N][M],num=1;
  9. for(i=0;i<N;i++){
  10. for(j=0;j<M;j++){
  11. a[i][j]=num;
  12. num++;
  13. }
  14. } //创建一个二维数组,元素从1 到N*M
  15. a[0][0]=0; //a[0][0]=1不是质数,将它赋值为0
  16. for(i=0;i<N;i++){
  17. for(j=0;j<M;j++){
  18. if(a[i][j]!=0){
  19. delete(a,a[i][j]); //调用函数进行筛选法 ,每调用函数一次数组a,a的值都会发生变化,不是质数的元素赋值为0
  20. }
  21. }
  22. }
  23. for(i=0;i<N;i++){
  24. for(j=0;j<M;j++){
  25. if(a[i][j]!=0){
  26. printf("%d\t",a[i][j]);
  27. }
  28. }
  29. } //将所有的指数(数组中不为0的数)输出
  30. return 0;
  31. }
  32. void delete(int s[N][M],int x){
  33. int i,j;
  34. for(i=0;i<N;i++){
  35. for(j=0;j<M;j++){
  36. if(i!=0||j!=0){ //跳过a[0][0],
  37. if(s[i][j]%x==0&&s[i][j]!=x){
  38. s[i][j]=0;//将所有的能被想整除的数赋值为0
  39. }
  40. }
  41. }
  42. }
  43. }

反思:

1.在做题之前好好读题,要读懂题的意思

2.不要固定自己的思维,一种方法不可以,可以换个方法。

3.当出现问题的时候,不要抱怨,自暴自弃,要多想一想





代码存放:

git

评论我的博客同学:

姜健https://i.cnblogs.com/EditPosts.aspx?postid=8778302

陆文奇:https://i.cnblogs.com/EditPosts.aspx?postid=8778302

党睿:https://i.cnblogs.com/EditPosts.aspx?postid=8778302

辛静瑶:https://i.cnblogs.com/EditPosts.aspx?postid=8778302

我所评论的同学:

姜健:http://www.cnblogs.com/jj990519/p/8763063.html

袁中:http://www.cnblogs.com/2719610441qqcom/p/8762037.html

王姝雯:http://www.cnblogs.com/phsudie/p/8759331.html

党睿:http://www.cnblogs.com/dangrui/p/8797836.html

辛静瑶:http://www.cnblogs.com/X-JY/p/8761685.html

知识点总结:

char *name[]={"Follow me","BASIC",......}

指针数组相当于二维数组;

name ——>二维数组的首元素的地址 =name[0]——>行指针——>第0行首元素的地址/第0个字符串的起始地址

name[1]——>行指针——>第一行首元素的地址 /第一个字符串的起始地址

*name——>列指针——>第0行第0列元素的地址/指向第0个字符串的第0个字符的地址

*(name+1)——>列指针——>第一行第0列元素的地址/指向第一个字符串的第0个字符的地址。

*(name+i)+n >第i行第n列元素的地址

((name+i)+n)>第i行第n列元素的值 例如 ((name+1)+1)=‘A’

链表其实就是结构递归定义,有一个头指针变量,还有表尾,表尾的地址部分放一个NULL表示链表结束。

形式

struct student{

int num;

float score;

......

struct student *next; //最主要的

};

在链表中要使用动态分配内存

malloc函数,malloc函数的返回值是一个分配域的起始地址

在链表中形式为:p=(struct student *)malloc(sizeof struct student );

对链表的操作:建立动态链表、输出、插入、删除;

建立链表的函数:

  1. struct student *creatvoid){
  2. struct student *head=NULL,*p=NULL,*q=NULL;
  3. p=q=(struct student *)malloc(sizeof(struct student));
  4. scanf("%d",&p->num);
  5. while(p->num!=0){
  6. if(head==NULL)head=p;
  7. else q->next=p;
  8. q=p;
  9. p=(struct student *)malloc(sizeof(struct student));
  10. scanf("%d",&p->num);
  11. }
  12. q->next=NULL;
  13. return(head);
  14. }

输出链表:

  1. void print(struct student *head){
  2. struct student *p;
  3. for(p=head;p!=NULL;p=p->next){
  4. printf("%d %f ...."p->num,p->score,.....);
  5. }
  6. }

删除节点:

  1. struct student *deleatstruct student *head,int num){
  2. struct student *p,*q;
  3. if(head!=NULL){
  4. for(p=head;p->next!=NULL&&p->num!=num;p=p->next){
  5. q=p;
  6. }
  7. if(p->num==num){
  8. if(p==head)head=p->next;
  9. else q->next=p->next;
  10. }
  11. }else{
  12. printf("没有找到");
  13. }
  14. return(head);
  15. }

插入节点:

  1. struct student *insertstruct student *headstruct student *stud){
  2. struct student *p,*q;
  3. if(head!=NULL){
  4. for(p=head;p->num!=stud->num&&p->next!=NULL;p=p->head){
  5. q=p;
  6. }
  7. if(p->num==stud->num){
  8. if(p==head){head=stud;stud->next=p;}
  9. else{q->next=stud;stud->next=p;}
  10. }else{p->next=stud;stud->next=NULL}
  11. }
  12. return(head);
  13. }

C高级第三次作业的更多相关文章

  1. C高级第三次作业(1)

    6-1 输出月份英文名 1.设计思路: 1.定义一个字符串数组将12个月的英文加进去: 2.判断输入的数是否大于等于1小于等于12: 3.若是 则返还s[n-1]; 4.否则返还NULL: 源代码: ...

  2. 软件工程(QLGY2015)第三次作业点评(含成绩)

    相关博文目录: 第一次作业点评 第二次作业点评 第三次作业点评 团队信息 本页点评团队1-22,其他组见:http://www.cnblogs.com/xiaozhi_5638/p/4490764.h ...

  3. 2018上C语言程序设计(高级)博客作业样例

    要求一(20分) 完成PTA中题目集名为<usth-C语言高级-第1次作业>中的所有题目. 要求二 PTA作业的总结(20分+30分) 将PTA第1次作业作业中以下2道题的解题思路按照规定 ...

  4. C程序第三次作业

    6-1 输出月份英文名 PTA提交列表: 1.设计思路 (1)主要描述题目算法 第一步:将十二个月的名称分别赋值给一维数组指针,定义用于返回的数据类型. 第二步:遍历数组,满足若n在1-12范围则将m ...

  5. C语言——第三次作业(2)

    作业要求一 PTA作业的提交列表 第一次作业 第二次作业 一道编程题: 有一个axb的数组,该数组里面顺序存放了从1到a*b的数字.其中a是你大学号的前三位数字,b是你大学号的后四位数字,比如你的学号 ...

  6. C高级第二次PTA作业

    6-7 删除字符串中数字字符 1.设计思路: (1)算法: 第一步:定义一个字符数组item,输入一个字符串赋给字符数组item.调用函数delnum, 第二步:在函数delnum中定义循环变量i=0 ...

  7. C语言--第三次作业

    要求一 . 1)C高级第三次PTA作业(1) 题目6-1 1.设计思路      (1)主要描述题目算法          第一步:将月份分别赋值:          第二步:利用switch语句,输 ...

  8. 北航OO第三单元作业总结(3.1~3.3)

    JML简介及相关工具链使用 1.JML规格描述语言介绍 本单元学习的内容是JML规格描述语言.我们知道,面向对象方法是一个抽象过程,需求者仅需关注方法的规格.规格是对一个方法/类/程序的外部可感知行为 ...

  9. 2003031121-浦娟-python数据分析第三周作业-第一次作业

    项目 内容 课程班级博客链接 https://edu.cnblogs.com/campus/pexy/20sj 作业链接 https://edu.cnblogs.com/campus/pexy/20s ...

随机推荐

  1. IDA 逆向工程 反汇编使用

    IDA pro 7.0版本 from:freebuf 用到的工具有IDA pro 7.0  ,被反汇编的是百度云(BaiduNetdisk_5.6.1.2.exe). 首先,IDA pro的长相如下: ...

  2. APP安全防护基本方法(混淆/签名验证/反调试)

    本教程所用Android Studio测试项目已上传:https://github.com/PrettyUp/SecTest 一.混淆 对于很多人而言是因为java才接触到“混淆”这个词,由于在前移动 ...

  3. Qt之获取子部件

    Qt5.10 QList<QObject*> list_children = this->children(); for(int i=0;i<list_children.siz ...

  4. 由于 Exception.tostring()失败,因此无法打印异常字符串

    console程序执行错误时,不显示异常信息. 解决方法: 在命令行修改显示字符格式  chcp 936

  5. js简单验证码的生成和验证

    如何用js生成简单验证码,并验证是否正确的方法 1.html页面如下 <div> <table border="0" cellspacing="5&qu ...

  6. linux下crontab的原理和用法

    linux 系统则是由 cron (crond) 这个系统服务来控制的.Linux 系统上面原本就有非常多的计划性工作,因此这个系统服务是默认启动的.另 外, 由于使用者自己也可以设置计划任务,所以, ...

  7. 【框架】PageObject(一)

    1.目的:为了将元素的find方法和业务逻辑分开来.如果元素的页面位置发生了变化,只需改动一个文件,而不影响业务的实现. 2.原理:一般一个页面对应一个class,在class里描述所有要用到的web ...

  8. LY.JAVA面向对象编程.工具类中使用静态、说明书的制作过程、API文档的使用过程

    2018-07-08 获取数组中的最大值 某个数字在数组中第一次出现时的索引 制作说明书的过程 对工具类的使用 获取数组中的最大值 获取数字在数组中第一次出现的索引值 API的使用过程 Math

  9. R语言常用操作

    1 取整运算 在编程实现的时候有时会碰到对数值取整的需求,而取整的方式却多种多样,依赖于具体问题,不过在R中已经配备了种类齐全的相关函数,主要包括以下五种: floor():向下取整: ceiling ...

  10. tomcat vue webpack vue-router 404

    社区已经有结局方案了, http://blog.csdn.net/hayre/article/details/70145513