白砂糖 发表于 2020-11-12 18:18:06

vs2019字符串的问题

本帖最后由 白砂糖 于 2020-11-12 18:19 编辑

1.定义任意两个字符串,完成以下操作:
(1)编写求字符串长度函数,显示该字符串长度;
(2)编写字符串拼接函数,将该字符串与键盘输入的另一字符串拼接,并显示拼接结果;
(3)编写比较大小函数,比较两字符串大小,并显示比较结果。




#include<iostream>
#include<string>
using namespace std;

class linklist
{
public:
        Str();
        Str(T a[], int n);
        ~Str();
        int Strlength();
        Strcat();
        StrCmp();
        void PrintList();
        int Empty();
private:
        Node<T>*first;


};
template<typename T>
linklist<T>::Str()
{
        first = nem Node<T>;
        first->next = nullptr;
}
template<typename T>
linklist<T>::Str(T a[], int n)
{
        first = new Node<T>;
        first->next = nullptr;
        for (i = 0; i < n; i++)
        {
                Node<T>*s = nullptr;
                s = new Node<T>;
                s->data = a;
                s->next = first->next;
                first->next = s;
        }

}
template<typename T>
linklist<T>::~Str()
{
        Node<T>*p = first;
        while (first != nullptr)
        {
                first = first->next;
                delete p;
                p = first;

        }
}
template<typename T>
int linklist<T>::Strlength()
{
        Node<T>*p = first->next;
        int count = 0;
        while (p != nullptr)
        {
                p = p->next;
                count++;

        }
        return count;
}
template<typename T>
linklist::Strcat()
{

}
template<typename T>
linklist::StrCmp()
{

}
template<typename T>
void PrintList()
{
        Node<T>*p = first->next;
        while (p != nullptr)
        {
                cout << p->data<<"\t";
                p = p->next;

        }
        cout << endl;
}
template<typename T>
int linklist::Empty()
{
        Node<T>*p = first->next;
       while (p = nullptr)
        {
                cout << "表为空。";
        }
           cout << endl;
}
int main()
{
        int r[], m[],x,y,i,j;
        for (i = 0; i < 10;i++)
        {
                cin >> x;
                r = x;
        }
        linklist L{ r,10};
        cout << "当前线性表r的数据为:";
        L.PrintList();
        cout << "当前字符串的长度为:" << L.Strlength() << endl;
        for (j = 0; j < 10;j++)
        {
                cin >> y;
                m = y;
        }
       
        linklist L{ m,10 };
        cout << "当前线性表m的数据为:";
        L.PrintList();
        cout << "当前字符串的长度为:" << L.Strlength() << endl;
        cout << "两个字符串链接后的数据为:" << L.Strcat() << endl;
        cout << "比较两个字符串的结果:" << L.StrCmp() << endl;
        return 0;
}

心驰神往 发表于 2020-11-13 14:49:47

有啥问题

乐乐学编程 发表于 2020-11-15 22:45:06

谢了

i6720 发表于 2020-11-16 05:08:17

多谢

白砂糖 发表于 2020-11-21 14:02:30

求求大佬,帮帮我吧,虽然没有技术含量,但是可以打发时间
页: [1]
查看完整版本: vs2019字符串的问题