zoukankan      html  css  js  c++  java
  • 作业

    #include<iostream>
    #include<malloc.h>
    using namespace std;
    int sum;
    struct LNode
    {
        char data;
        struct LNode * next;
    };
    void f1(LNode *&L)
    {
        LNode *s,*r;
        int n;
        L=(LNode *)malloc(sizeof(LNode));
        cout<<"请输入元素的个数:"<<endl;
        cin>>n;
        r=L;
        for(int i=0;i<n;i++)
        {
            s=(LNode *)malloc(sizeof(LNode));
            cin>>s->data;
            sum++;
            r->next=s;
            r=s;
        }
        r->next=NULL;
    }
    void f2(LNode *&L)
    {
        LNode *r=L,*s;
        while(r->next)
        {
            r=r->next;
        }
        s=(LNode *)malloc(sizeof(LNode));
        cin>>s->data;
        s->next=NULL;
        r->next=s;
        sum++;
    }

    void f3(LNode *&L)
    {
        LNode *s;
        s=L->next;
        while(s)
        {
            cout<<s->data;
            s=s->next;
        }
    }
    void f4()
    {
        cout<<sum<<endl;
    }
    void f5()
    {
        if(sum==0)
            cout<<"空"<<endl;
        else cout<<"非空"<<endl;
    }
    void f6(LNode *&L)
    {
        LNode *s=L;
        int n;
        cout<<"您要输出第几个元素n:"<<endl;
        cin>>n;
        while(n--)
        {
            s=s->next;
        }
        cout<<s->data;
    }
    void f7(LNode *&L)
    {
        int n=0;
        char c;
        cout<<"请输入要查询的元素:"<<endl;
        cin>>c;
        LNode *s=L;
        while(s->data!='c'&&s)
        {


    int main()
    {
    //    int n;
        sum=0;
        LNode *L;
        cout<<"1:初始化一个链表并且输入元素"<<endl;
        cout<<"2:插入1个元素(尾查法)"<<endl;
        cout<<"3:输出链表"<<endl;
        cout<<"4:输出链表长度"<<endl;
        cout<<"5:判断链表是否为空"<<endl;
        cout<<"6:输出第i个元素"<<endl;
        cout<<"7:输出元素的位置"<<endl;
        cout<<"8:在第i个位置上插入元素"<<endl;
        cout<<"9:删除第i个元素"<<endl;
        cout<<"10:释放链表"<<endl;
        f1(L);
        f6(L);
        return 0;
    }

  • 相关阅读:
    L317 电子烟
    L316 波音737Max 危机
    2.19.3月 专业综合错题
    L314 单音节词读音规则(二)-元音字母发音规则
    L313 珊瑚裸鼠灭绝
    L312 难看懂的
    Pycharm写代码中文输入法不跟随
    Windows下Python多版本共存
    Python之批处理字符串(打开文件)
    Python Url请求代码
  • 原文地址:https://www.cnblogs.com/zhangdashuai/p/3640373.html
Copyright © 2011-2022 走看看