c/c++语言开发共享判断一个非空单链表是否是递增有序的

直接附上代码,不理解请看置逆那篇,链接:https://www.cnblogs.com/biaobiao88/p/12042132.html #include<bits/stdc++.h> #define int long long using namespace std; typedef stru …

直接附上代码,不理解请看置逆那篇,链接:

#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; }

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/c-cdevelopment/600697.html

(0)
上一篇 2021年5月9日
下一篇 2021年5月9日

精彩推荐