#include <list> 

std::list<int> nodes;

void listStuff();

void setup() {
  Serial.begin(115200);

  nodes.push_back(123);
  nodes.push_back(456);
  nodes.push_back(789);

  int myNodeId = 456;
}

void loop()
{
  listStuff();
}


void listStuff() {
  int masterNodeId = UINT32_MAX ;
  int numNodes = nodes.size();

  nodes.sort();
  std::list<int>::iterator nodeIterator = nodes.begin();

  int j = 0;
  while( nodeIterator != nodes.end() ) {
    if( *nodeIterator < masterNodeId ) {
      masterNodeId = *nodeIterator ;
    }
    Serial.println(*nodeIterator); // print out the list
    nodeIterator++;

    // determine our NodeID
    // TODO: sort list first
    if( (int)*nodeIterator == (int)myNodeId ) {
      _nodePos = j;
      Serial.print("My Node Pos: ");
      Serial.println(_nodePos);
    }
    j++;
  }

  Serial.print("Masternode: ");
  Serial.println(masterNodeId);
}