#Anybody know why the sort and unique functions wouldn't work in a linux system?

1 messages · Page 1 of 1 (latest)

thick atlas
#

I am creating a program in C++ that utilizes the sort and unique functions to sort a vector array and get rid of duplicates. Here is my code:

// Sort tokens that need to be sorted for output
auto numsEqual = [](const LexItem& element1, const LexItem& element2)
{
    return stod(element1.GetLexeme()) == stod(element2.GetLexeme());
};

auto stringsEqual = [](const LexItem& element1, const LexItem& element2)
{
    return element1.GetLexeme() == element2.GetLexeme();
};

sort(nconsts.begin(), nconsts.end(), compareNconsts);
nconsts.erase( unique( nconsts.begin(), nconsts.end(), numsEqual ), nconsts.end() );

sort(idents.begin(), idents.end(), compareStrings);
idents.erase(unique(idents.begin(), idents.end(), stringsEqual ), idents.end() );
sort(sconsts.begin(), sconsts.end(), compareStrings);

sconsts.erase(unique(sconsts.begin(), sconsts.end(), stringsEqual ), sconsts.end() );
sort(bconsts.begin(), bconsts.end(), compareStrings);
// sconsts.erase(unique(sconsts.begin(), sconsts.end(), stringsEqual ), sconsts.end() );

The problem is, when I output the array it appears that it has not been sorted at all, and duplicates have not been removed either. It works in clion in my windows system, but when I paste it into linux (vocareum auto grader) it doesn't pass any test cases because the output is not sorted and there are duplicates. I am new to c++ and have been trying to debug this but debugging within vocareum is very hard, can anybody help? I am willing to paste more code if needed, just lmk

These are my imports btw

#include <iostream>
#include <sstream>
#include <cstring>
#include <regex>
#include <string>
#include <fstream>
#include <map>
#include <algorithm>
#include <map>
#include "lex.h"
using namespace std;
desert jayBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

bright cypress
#

Is that code in a function?

thick atlas
#

nope

bright cypress
#

Post more code then.

thick atlas
#

alright, i held off on it bc even i can tell its very bloated and innefficient

#

one sec

#

The sort and unique functions are towards the end of the file

bright cypress
#

This is not usual then.

thick atlas
#

it might be the result of something else im trying to narrow it down to see if its actually sort and unique thats not working

#

it is extremely difficult to debug on this scuffed auto grader platform

bright cypress
#

Maybe wresting with the debugger on there might be worth it.

thick atlas
#

worst case scenario i just reimplement using sets or smthn

#

ok it might be due to the version of c, the auto grader uses c++11

#

guess I'll have to use something else

midnight folio
# thick atlas

maybe because in your compareStrings uses strcmp but your stringsEqual doesn't

thick atlas
#

nah i fixed it using sets

#

thanks guys

#

!solved