大佬,求教c++

cj云 2021-05-25 09:36:02
#include<iostream> #include<stdio.h> using namespace std; #define ok 0 #define error -1 #define max 7 typedef char typeelem; typedef int status; typedef struct no {     struct no *next;     typeelem data; } noe, *noa; typedef struct noc {     noa tail, head;     int leng; } sqlist; status initlist(sqlist &L);//创建一个空的链式线性表 status shuzhi(sqlist &L);//对表进行创建max大小链式表 status traverselist(sqlist L);//对链式表进行遍历 status getelem(sqlist L, int i);//在链式表中将第i个元素取出 status locateelem(sqlist L, typeelem e, int c);//在链式表中找值为e的结点并找第c个结点的值 status listinsert(sqlist &L, int d, typeelem a);//链式表中插入值 status listdelete(sqlist &L, int b);//删除值为b的结点 status nextelem(sqlist L, typeelem e); status priorelem(sqlist L, typeelem e); status clearlist(sqlist &L); status destroylist(sqlist &L); int main() {     sqlist L;     int i, d, c, b;     typeelem e, a;     initlist(L);     cout << "put max=" <<" " <<max << " elem" << endl;     shuzhi(L);    /* cout << "traverselist" << endl;     traverselist(L);     cout << "put i from 1-" << max << endl;     cin >> i;     getelem(L, i);     cout << "seek number c and elem e" << endl;*/     cin >> e;     /*locateelem(L, e, c);     cout << "listinsert"<< "put nuumber d" << endl;     cin >> d;     cout << "elem a" << endl;     cin >> a;     listinsert(L, d, a);     cout << "traverselist" << endl;     traverselist(L);     cout << "listdelete" << "put number b" << endl;     cin >> b;     listdelete(L, b);     cout << "nextelem" << endl;*/     nextelem(L, e);     priorelem(L, e);     clearlist(L);     destroylist(L);     // cout << "traverselist" << endl;     traverselist(L);     return ok; } status initlist(sqlist &L) {     L.head = new noe[1];     if(!L.head)     {         cout <<"\bfailure to open up space" << endl;         return error;     }     else         L.tail = L.head;         L.leng = 0; } status shuzhi(sqlist &L) {        noa q;        L.leng = max;        for (int i = 0; i < L.leng; i++)        {            q = new noe[1];            if (!q)            {                cout << "failure to open up space" << endl;                return error;            }            cin >> q->data;            L.tail->next = q;            L.tail = q;            q->next = NULL;     }         return ok; } status traverselist(sqlist L) {     noa p;     p = L.head->next;     if (p == NULL)     {         cout << "the list is empty" << endl;         return error;     }         for (int i = 0; i < L.leng; i++)         {             cout << p->data << endl;             p = p->next;         }     return ok; } status getelem(sqlist L, int i) {     int j;     noa q = L.head;     if(max<i<0)     {         cout << "i is error" << endl;         return error;     }     else     for (j = 1; j <= i; j++)     {         q = q->next;     }     cout << q->data << endl;     return ok; } status locateelem(sqlist L, typeelem e, int c) {     c = 1;     noa q = L.head->next;        while(q->data != e && q->next!=NULL)         {             q = q->next;             c++;         }      if(q->data!=e)         {             cout << c+1 << "isn't ture" << endl;             return error;         }         else         {             cout << "the potition is" << c << endl;             cout << q->data << endl;                 return ok;        }      } status listinsert(sqlist &L, int d, typeelem a) {     int i;     noa q=L.head->next;     noa p=new noe[1];     for (i=1; i<d-1; i++)     {         q = q->next;     }     p->data = a;     p->next = q->next;     q->next = p;     L.leng++; } status listdelete(sqlist &L, int b) {     int i;     if(b<1||b>L.leng)         return error;     noa p = L.head->next;     noa q;     for (i = 1; i < b-1; i++)     {         p = p->next;     }     q = p->next;     p->next = p->next->next;     delete[] q;     L.leng--; } status nextelem(sqlist L, typeelem e) {     int c=1;     noa q = L.head->next;     while (e != q->data && q->next != NULL)         {             q = q->next;             c++;         }         c++;         if (c > L.leng)         {             cout << e <<" doesn't have next elem" << endl;             return ok;  }         else          {             cout << e << " have next elem" << endl;             q = q->next;             cout << "the elem is" <<" "<<q->data << endl;             return ok;         } } status priorelem(sqlist L, typeelem e) {     noa q;     noa p = L.head->next;     if(e==p->data)     {         cout << e << " " << "doesn't have prior elem" << endl;         return ok;     }     while (e != p->data && p->next != NULL)     {         q = p;         p = p->next;     }     cout << e << ""<< " have prior elem" << endl;     cout << "the elem is " << q->data << endl;     return ok; } status clearlist(sqlist &L) {     noa p = L.head->next;     noa q;     L.tail = L.head;     while (p != NULL)     {         q = p;         p = p->next;         delete[] q;     }     return ok; } status destroylist(sqlist &L) {     noa p=L.head;     noa q;     L.tail = L.head;     while (p != NULL)     {         q = p;         p = p->next;         delete[] q;     }     return ok; }    我想询问一下destroylist函数的毁表为什么进行不下去,而且毁和清空有什么区别
...全文
181 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2021-05-26
  • 打赏
  • 举报
回复
数据结构对单链表进行数据排序 http://bbs.csdn.net/topics/392201633

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧