# 作业要求一

## 6-1 输出月份英文名

1.设计思路

2.流程图

3.实验代码

char *getmonth( int n )
{
char *month[]={"January","February","March","April","May","June","July","August","September","October","November","December"};
if(n<1||n>12)
{
return NULL;
}
else{
return *(month+n-1);
}
}



4.问题及解决方法

## 6-2查找星期

1.设计思路

2.实验代码

int getindex( char *s )
{
int i,a=-1;
char day[7][10]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
for(i=0;i<7;i++)
{
if(strcmp(s,day[i])==0)
a=i;
}
return a;
}



3.问题及错误

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

1.设计思路

2.实验代码

int max_len(char *s[],int n)
{
char *a;
int i;
a=s[0];
for(i=1;i<n;i++)
{
if(strlen(a)<strlen(s[i]))
{
a=s[i];
}

}
return strlen(a);
}


3.问题及错误

# 作业要求三

## 6-1 奇数值结点链表

1.设计思路
2.实验代码

struct ListNode *readlist()
{
int data;
struct ListNode *p;
while(scanf("%d",&data)&&data!=-1)
{
struct ListNode *q=(struct ListNode*)malloc(sizeof(struct ListNode));
if(q!=NULL)
{
q->data=data;
q->next=NULL;
}
else exit(1);
{
p->next=q;
}
p=q;
}
}
struct ListNode *getodd( struct ListNode **L )
{
while((*L)!=NULL)
{
int data=(*L)->data;
struct ListNode *q=(struct ListNode*)malloc(sizeof(struct ListNode));
if(data%2)
{
if(q!=NULL)
{
q->data=data;
q->next=NULL;
}
else exit(1);
{
p1->next=q;
}
p1=q;
}
else
{
if(q!=NULL)
{
q->data=data;
q->next=NULL;
}
else exit(1);
{
p0->next=q;
}
p0=q;
}
*L=(*L)->next;
}
}


## 6-2 学生成绩链表处理

2.实验代码

struct stud_node *createlist()
{
int num;
scanf ("%d", &num);
while (num != 0)
{
q = (struct stud_node *)malloc (sizeof (struct stud_node));
scanf ("%s %d", q->name, &q->score);
q->num = num;
q->next = NULL;
else
tail->next = q;
tail = q;
scanf ("%d", &num);
}
}
struct stud_node *deletelist( struct stud_node *head, int min_score )
{
struct stud_node *ptr1, *ptr2;
{
free(ptr2);
}
return NULL;
while (ptr2 != NULL)
{
if (ptr2->score < min_score) {
ptr1->next = ptr2->next;
free(ptr2);
}
else
ptr1 = ptr2;
ptr2 = ptr1->next;
}
}


## 6-3 链表拼接

2.实验代码

struct ListNode *mergelists(struct ListNode *list1, struct ListNode *list2)
{
int num = 0;
int temp[100];
struct ListNode  *p = list1;
while(p != NULL)
{
temp[num] = p->data;
num++;
p = p->next;
}
p = list2;
while(p != NULL)
{
temp[num] = p->data;
num++;
p = p->next;
}
int i,j;
for(i = 0; i < num; i++)
for(j = i + 1; j < num; j++)
{
if(temp[i] > temp[j])
{
int t;
t = temp[i];
temp[i] = temp[j];
temp[j] = t;
}
}
struct ListNode  *newlist = NULL;
struct ListNode  *endlist = NULL;
struct ListNode  *q;
for(i = 0; i < num; i++)
{
q = (struct ListNode  *)malloc(sizeof(struct ListNode));
q->data = temp[i];
if(newlist == NULL)
{
newlist = q;
newlist->next = NULL;
}
if(endlist != NULL)
{
endlist->next = q;
}
endlist = q;
endlist->next = NULL;
}
return newlist;
}


posted on 2018-04-22 20:11  Doyol  阅读(178)  评论(2编辑  收藏  举报