اذهب إلى المحتوى
  • 0

كيف يمكني عمل فنكشن . AddBack and AddInOrder

Mari Carmen

السؤال

Recommended Posts

  • 0

سأعطيك إجابة عن التمرين بإعتماد الدوال التي طلبوها منك

STL::STL (string S, string language) {
	s = S;
	lang = language;
}

string STL::gets () {return s;}//returns the string of the word.

STL * STL::getlang () {return lang;}//returns the lang.

void STL::print() {cout << s << endl;}

void LLN::AddFront (string S) { //Adds a word (If one does't already exist) into the back of the list.
    string temp1 = S;
    string temp2 = this->s;
    int i = 0;
    while(temp2[i])
    {
        temp2[i] = tolower(temp2[i]);
        i++;
    }
    i = 0;
    while(temp1[i])
    {
        temp1[i] = tolower(temp1[i]);
        i++;
    }
    if (temp1 == temp2) return;
	if (lang==NULL) next = new STL (S,NULL);
	else lang->addback (S);
}

void LLN::AddBack (string S) { //Adds a word (If one does't already exist) into the back of the list.
    string temp1 = S;
    string temp2 = this->s;
    int i = 0;
    while(temp1[i])
    {
        temp1[i] = tolower(temp1[i]);
        i++;
    }
    i = 0;
    while(temp2[i])
    {
        temp2[i] = tolower(temp2[i]);
        i++;
    }
    if (temp2 == temp1) return;
	if (lang==NULL) next = new STL (S,NULL);
	else lang->addback (S);
}

void STL::AddInOrder (string S) { //Adds a word in alphabetical order. We do a check here to determine whether or not the word we're probing for exists.
    string tempS = this->gets();
    for (int i = 0; i < S.length(); i++)
    {
        S[i] = tolower(S[i]);
    }
    for (int i = 0; i < tempS.length(); i++)
    {
        tempS[i] = tolower(tempS[i]);
    }
    if (!lang || S < lang->gets()){
    lang = new STL (S,next);
    }
	else
		lang->addinorder (S);

}

void STL::Sort () {  //Sort all the words in the list starting with me in reverse order
	print ();
	if (lang != NULL) lang->Sort ();
}

كملاحظة : خلال كل العملية نقوم بتصغير حروف الـstring بإعتماد مصفوفة tolower

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...