Yep this might help, but i still can't run this code and i dont't know if it's normal.
Maybe you forgot to link the 3 libraries? (system,graphics,window).
Paste more infos!
If I copy my code and compile it, it works.
@Mindiell:
Thank you
I finally got it.
But it's not the result that I want.
Compile it and you will see that the points are going to be sorted.
But it's also flickering. I want it like this:
the current code is here:
#include <SFML/Graphics.hpp>
#include <iostream>
#include <vector>
#include <cstdlib>
sf::RenderWindow App(sf::VideoMode(800, 600), "J4F");
typedef std::vector<int> fieldType;
class Field
{
std::vector<sf::Shape> m_points;
public:
// fill 'm_points'
void fill(const fieldType& field)
{
std::size_t y = 0;
for(std::size_t i = 0; i < field.size(); i++)
{
sf::Shape point(sf::Shape::Circle(0.0, 0.0, 2, sf::Color::Red));
point.SetPosition(field[i], y++);
//std::cout << "x: " << point.GetPosition().x << " y: " << point.GetPosition().y << std::endl;
this->m_points.push_back(point);
App.Draw(point);
}
}
void sort()//bubble
{
for(std::size_t o = this->m_points.size()-1;o > 0; --o)
{
for(std::size_t pos = 0; pos < o; ++pos)
{
if(this->m_points[pos].GetPosition().x > this->m_points[pos+1].GetPosition().x)
{
sf::Vector2f tmp_pos = this->m_points[pos].GetPosition();
this->m_points[pos].SetPosition(this->m_points[pos+1].GetPosition());
this->m_points[pos+1].SetPosition(tmp_pos);
}
}
}
for(std::size_t i = 0; i < this->m_points.size(); i++)
{
this->m_points[i].SetPosition(this->m_points[i].GetPosition().x, i);
//std::cout << "x: " << this->m_points[i].GetPosition().x << " y: " << this->m_points[i].GetPosition().y << std::endl;
App.Display(); // bad?
sf::Sleep(0.01); // not really that what I wanted.
App.Draw(this->m_points[i]);
}
}
};
int main()
{
Field fieldContext;
std::vector<int> field;
for(int i = 0; i < 1000; i++)
field.push_back(i);
std::random_shuffle(field.begin(), field.end());
std::cout << "Filling..." << std::endl;
fieldContext.fill(field);
App.Display();
std::cin.get();
std::cout << "Sorting..." << std::endl;
fieldContext.sort();
App.Display();
std::cin.get();
return 0;
}
thanks again dude! :wink: