2019春第十二周作业

|--------|:------|
|这个作业属于那个课程|C语言程序设计II|
|这个作业要求在哪里|https://edu.cnblogs.com/campus/zswxy/software-engineering-class2-2018/homework/3234|
|我在这个课程的目标是|<使用链表>|
|这个作业在那个具体方面帮助我实现目标|<深化链表知识>|
|参考文献||

基础作业

1.函数题:计算最长的字符串长度

用strlen计算类似于求一维数组的最大值

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

2.函数题:统计专业人数

用计数器记录字符串第二三个是否为02就可以了

int countcs( struct ListNode *head )
{
    int flag=0;
    while(head)
    {
        if(head->code[1]=='0'&&head->code[2]=='2')
        flag++;
        head=head->next;
    }
    return flag;
}

3.函数题:删除单链表偶数结点

翻书仔细看了下才会建立的单链表

struct ListNode *createlist()
{
	int x;
    struct ListNode *head=NULL,*q=NULL,*p;
    scanf("%d",&x);
    while(x!=-1)
    {
    	
        p=(struct ListNode*)malloc(sizeof(struct ListNode));
        p->data=x;
        if(head==NULL)
        head=p;
        else
        q->next=p;
        q=p;
        scanf("%d",&x);
    }
    q=NULL;
    return head;
}
struct ListNode *deleteeven( struct ListNode *head )
{
    struct ListNode *tou=NULL,*p=NULL;
    while(head)
    {
        if(head->data%2!=0)
        {
            if(tou==NULL)
            {
                tou=head;
                p=tou;
            }
            else
            {
                tou->next=head;
                tou=head;
            }
        }
        head=head->next;
    }
    if(tou!=NULL)
    tou->next=NULL;
    return p;
}
原文地址:https://www.cnblogs.com/yikejiushidouxing/p/10859261.html