判断一个非空单链表是否是递增有序的

直接附上代码,不理解请看置逆那篇,链接:https://www.cnblogs.com/biaobiao88/p/12042132.html

#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef struct
{
    int len;
    int *next;
}node;

//判断一个非空单链表是否是递增有序的 
void Inceart(node *list)
{
    int flag = 0;
    for(int i = 0;i < list->len;i++)
    {
        if(list->next[i] > list->next[i + 1])
        {
            flag = 1;
            break;
        }
    }
    if(flag == 1)
    {
        cout << "此非空单链表不是递增有序的" << endl;
        return ;
    }
    if(flag == 0)
    {
        cout << "此非空单链表是递增有序的" << endl;
        return ;
    }
}

signed main()
{
    node *list;
    list = (node *)malloc(sizeof(node));
    cout << "输入顺序表长度:";
    cin >> list->len;
    list->next = (int *)malloc(sizeof(int)*list->len);
    
    cout << "输入顺序表元素:";
    for(int i = 0;i < list->len;i++)
        cin >> list->next[i];
    
    Inceart(list); 
    free(list->next);
   free(list);
return 0; }
posted @ 2019-12-15 11:01  恶魔岛  阅读(2686)  评论(1编辑  收藏  举报