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

### 2、实验代码

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

## 6-2 查找星期

### 2、实验代码

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

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

### 2、实验代码

int max_len( char *s[], int n )
{
int i,len=0,max=0;
for(i=0;i<n;i++)
{
len=strlen(s[i]);
if(len>max)
{
max=len;
}
}
return max;
}

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

### 2、实验代码

char *match( char *s, char ch1, char ch2 )
{
int i,j=strlen(s),k = 0,m=0;
char *temp;
for(i=0;s[i] != '\0';i++)
{
if(s[i] == ch1)
{
temp = &s[i];
j = i;
break;
}
}
for(i=j;s[i] != '\0';i++)
{
if(s[i] != ch2)
{
printf("%c",s[i]);
} else
{
printf("%c\n",s[i]);
return temp;
}
}
printf("\n");
return temp;
}

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

### 2、实验代码

{
int number;
struct ListNode *p = NULL,*head = NULL,*tail = NULL;
scanf("%d",&number);
while(number!=-1&&number>0 ) {
p = (struct ListNode*)malloc(sizeof(struct ListNode));
p->data = number;
} else {
tail->next = p;
}
tail = p;
scanf("%d",&number);
}
return NULL;
}
tail->next = NULL;
}
struct ListNode *getodd( struct ListNode **L )
{
struct ListNode *p = *L,*head1 = NULL,*r = NULL,*L1 = NULL,*r1 = NULL;
while(p!=NULL&&p->data>0)
{
if(p->data%2!=0)
{
{
}else
{
r->next = p;
}
r = p;
} else
{
if(L1 ==NULL)
{
L1 = p;
} else
{
r1->next = p;
}
r1 = p;
}
p = p->next;
}
return NULL;
} else
{
r->next = NULL;
}
if(L1==NULL)
{
*L = NULL;
} else
{
r1->next = NULL;
*L = L1;
}
}

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

### 2、实验代码

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

3、本题调试过程碰到的问题及解决办法

4、提交列表

## 6-3 链表拼接

### 2、实验代码

struct ListNode *mergelists(struct ListNode *list1, struct ListNode *list2)
{
struct ListNode *h,*p,*i,*k;
h=(struct ListNode*)malloc(sizeof(struct ListNode));
p=h;
i=list1;
k=list2;
while(i!=NULL&&k!=NULL)

{
if(i->data<k->data)
{
p->next=i;
i=i->next;
}
else
{
p->next=k;
k=k->next;
}
p=p->next;
}
while(i)
{
p->next=i;
i=i->next;
p=p->next;
}
while(k)
{
p->next=k;
k=k->next;
p=p->next;
}
p->next=NULL;
return h->next;
}

## 我的git地址：

https://coding.net/u/zhouxuan12/p/123/git?public=true

## 图表

posted on 2018-04-22 23:02  周璇A  阅读(158)  评论(0编辑  收藏  举报