Is there any way in pure C to implement set?

4

I'm doing a job for college and I need to check word for word from a "dictionary" in file txt and compare those words with the words of an array that was provided.

In order to make my life easier (as I'll have to figure out some way to make my program faster), is there in C the possibility of using set variables? For example, the "sets" of Python. Or do I have to do everything "in the hand" anyway?

    
asked by anonymous 14.12.2015 / 20:44

3 answers

2

Not directly, you will have to implement the data structure.

A library that already implements this is GNULib . But until you make it work, you've already turned around. It's only worth it for more intensive use, not for breaking a branch.

    
14.12.2015 / 20:51
0

I think that in C you can not use functions like the ones in Python Set, comparisons should be made "manually", you could use a vector to store all words and compare them through a loop of repetition. / p>

If you are comparing only one information with another information you can use a simple vector, but if you need to compare more than one information at a time, you can do a struct and make an array of structs.

    
14.12.2015 / 22:56
-3

You can do this in C ++, change the extension from .c to .cpp and use the g ++ compiler instead of gcc . You can use vector , set , queue , map , ...
have several, take a look at: link

Example:

#include <vector>
#include <iostream>

int main()
{
    std::vector<int> numbers;

    numbers.push_back(42);
    numbers.push_back(314159); 

    for (int i : numbers) { // c++11 range-based for loop
        std::cout << i << '\n';
    } 

    return 0;
}
    
14.12.2015 / 21:58