构建长度为2的升序链表
#pragma once
#include<stdlib.h>
typedef int ElemType;
typedef struct LNode {
ElemType data;
struct LNode* next;
}LNode,*LinkList;
LinkList CreateOrdLList(ElemType x, ElemType y);
#include "allinclude.h" //DO NOT edit this line
LinkList CreateOrdLList(ElemType x, ElemType y) {
// Add your code here
LinkList head = (LinkList)malloc(sizeof(LNode));
if (head == NULL)
return NULL;
if (head)
{
head->next = (LinkList)malloc(sizeof(LNode));
if (head->next)
{
head->next->next = NULL;
}
else return NULL;
}
if (x < y)
head->data = x, head->next->data = y;
else
head->data = y, head->next->data = x;
return head;
}
?