Skip to content

Instantly share code, notes, and snippets.

@stKhaDgar
Created November 26, 2017 20:00
Show Gist options
  • Save stKhaDgar/987317ddb307a5acf3cab8a4f1548047 to your computer and use it in GitHub Desktop.
Save stKhaDgar/987317ddb307a5acf3cab8a4f1548047 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
using namespace std;
string List::filter(std::string _type, int _cond, int _wifi)
{
if (size() > 0)
{
string print = "";
int numOfStr = 1;
unsigned int maxOfElInStr = 0;
for (auto ptr = begin(); ptr != end();)
{
ElementIDK *temp = ptr;
// Filter by the first argument (string)
if (ptr->get_Type() == _type)
{
temp = ptr;
}
else if(_type == "")
{
temp = ptr;
}
else
{
temp = NULL;
}
// Filter by the second argument (int)
if(_cond != 2 && temp != NULL)
{
if (ptr->get_smthngOne() == _cond)
{
temp = ptr;
}
else
{
temp = NULL;
}
}
else if (_cond == 2 && temp != NULL)
{
temp = ptr;
}
// Filter by the third argument (int)
if(_wifi != 2 && temp != NULL)
{
if (ptr->get_smthngTwo() == _wifi)
{
temp = ptr;
}
else
{
temp = NULL;
}
}
else if (_wifi == 2 && temp != NULL)
{
temp = ptr;
}
// Find the maximum number of elements in a string
for (auto ptr = begin(); ptr != end();)
{
string numOfElInStr = ptr->get_TypeOfRC();
if (maxOfElInStr < numOfElInStr.size())
{
maxOfElInStr = numOfElInStr.size();
}
ptr = ptr->next;
}
string Type = ptr->get_Type();
// To dynamically display the list
for (Type.size(); Type.size() < maxOfElInStr;)
{
Type = Type + " ";
}
// If the object is not NULL - display it
if (temp != NULL)
{
print = print + " " + to_string(numOfStr) + ". " + " + _type + _cond + _wifi;
}
numOfStr++;
ptr = ptr->next;
}
return print;
}
else
{
return "There are no items matching the filter in the list.";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment