AnyviewC第九章(按需自取)

9.023

AnyviewC第九章(按需自取)_第1张图片

#include "allinclude.h"  //DO NOT edit this line
char* oldest(struct student s[], int n)
{ // Add your code here
    int i=0,j=0;
    for(i=0;is[j].birth.year)
        {
            continue;
        }
        else if(s[i].birth.years[j].birth.month)
            {
            continue;
            }
            else if(s[i].birth.months[j].birth.day)
                {
                continue;
                }
                else if(s[i].birth.day

9.033

AnyviewC第九章(按需自取)_第2张图片

#include "allinclude.h" //DO NOT edit this line
char *oldest(struct studentNode *L)
{
    struct studentNode *p;
    if(L==NULL)
        return NULL;//若L是空表,则返回空指针null
    for(p=L;p!=NULL;p=p->next)//使p指向L的下一个人的内容
    {
         if(L->birth.year>p->birth.year)
            L=p;//L指向第一个人的年份,p指向第二个人的年份
         else if(L->birth.year==p->birth.year)
         {
              if(L->birth.month>p->birth.month)
                L=p;
              else if(L->birth.month==p->birth.month)
              {
                 if(L->birth.day>p->birth.day)
                    L=p;
              }
         }
    }
    return L->name;
}

9.063

AnyviewC第九章(按需自取)_第3张图片

#include "allinclude.h"  //DO NOT edit this line
float creditSum(struct course c[], int n, int s)
{  // Add your code here
    int i=0;
    float sum=0.0;
    for(i;i

9.073

AnyviewC第九章(按需自取)_第4张图片

#include "allinclude.h"  //DO NOT edit this line
float creditSum(struct courseNode* Lc, int s)
{  // Add your code here
	float sum=0.0;
  	struct courseNode *p;
    if(Lc==NULL)
    {
		return sum;
    }
	else 
    {
        for(p=Lc;p!=NULL;p=p->next)
        {
            if(p->semester==s)
            {
                sum+=p->credit;
            }
        }
    }
    return sum;
}

9.133

AnyviewC第九章(按需自取)_第5张图片

#include "allinclude.h"  //DO NOT edit this line
struct studentNode* CreateLinkList(struct student s[], int n)
{  // Add your code here
	struct studentNode* L,*p0;
    L = (studentNode*) malloc (sizeof(studentNode));
    L->next=NULL; 
    struct student *x;
    if (NULL==s || n==0) 
    {
        return NULL;
    }    
    x=s;       
    L->birth.year=x->birth.year;
    L->birth.month=x->birth.month;
    L->birth.day=x->birth.day;
    strcpy(L->name,x->name);
    x++;
    p0=L;
    for (;xbirth.year=x->birth.year;
        p->birth.month=x->birth.month;
        p->birth.day=x->birth.day;
        strcpy(p->name,x->name);
        p->next=p0->next;
        p0->next=p;
        p0=p0->next;        
    }   
    return L;
}

9.173

AnyviewC第九章(按需自取)_第6张图片

#include "allinclude.h"  //DO NOT edit this line
struct courseNode* creditChange(struct courseNode* Lc, int c, float t)
{ // Add your code here
   struct courseNode*p;
   p=Lc;
   for(p=Lc;p!=NULL;p=p->next)
   {
      if(p->cID==c)
      {
         p->credit=t;
         return p;
      }
   }
   return NULL; // This is temporary code. Modify it if necessary.
}

9.183

AnyviewC第九章(按需自取)_第7张图片

#include "allinclude.h"  //DO NOT edit this line
struct courseNode* deleteCourse(struct courseNode** Lc, int c)
{  // Add your code here
    struct courseNode *current = *Lc;
    struct courseNode *previous = NULL;
    // 遍历链表找到课程号为c的结点
    while (current != NULL && current->cID != c) {
        previous = current;
        current = current->next;
    }
    // 如果课程号为c的结点不存在,返回NULL
    if (current == NULL) {
        return NULL;
    }
    // 如果找到了课程号为c的结点
    if (previous == NULL) {
        // 如果该结点是链表的第一个结点
        *Lc = current->next;
    } else {
        // 如果该结点不是链表的第一个结点
        previous->next = current->next;
    }
    return current;
}

9.302

AnyviewC第九章(按需自取)_第8张图片

#include "allinclude.h"  //DO NOT edit this line
struct node* inverse(struct node* L)
{ // Add your code here
	struct node *t,*p;
	p=L;
	L=NULL;
	while(p!=NULL)
	{
    	t=p->next;
    	p->next=L;
    	L=p;
    	p=t;
	}
	return L;
}

9.325

AnyviewC第九章(按需自取)_第9张图片

#include "allinclude.h"  //DO NOT edit this line
struct node* sorting(struct node* L)
{  // Add your code her
    struct node *pb,*pf,temp;
    pf=L;
    if(L==NULL)//链表为空
    {
        return L;
    }
    if(L->next==NULL)//链表有1个节点
    {
        return L;
    }
    while(pf->next!=NULL)//以pf指向的节点为基准节点
    {
        pb=pf->next;//pb从基准点的下一个节点开始
        while(pb!=NULL)
        {
            if(pf->ch>pb->ch)
            {
                temp=*pf;
                *pf=*pb;
                *pb=temp;
                temp.next=pf->next;
                pf->next=pb->next;
                pb->next=temp.next;
            }
            pb=pb->next;
        }
        pf=pf->next;
    }
    return L;
}

你可能感兴趣的:(算法,前端)