hi
I was hoping someone might be able to advise me please
I would like to create a dynamic list of numbers
I need to be able to add numbers to the list, remove a number from the list and report the size of the list
I tried this library [Published on GitHub] LinkedList Class (Fully implemented) - Libraries - Arduino Forum
but i don't think it does all what i want. but i may be wrong (as usual
).
in the example code below i have set to read from the serial monitor
so my scenario might be
if i press b it add 98 to the list (the sketch does that )
if i press n it adds 110 to the list (the sketch does that )
i might then press b again which adds another 98 to the list (the sketch does that )
if i press m it adds 109 to the list (the sketch does that )
so i now have a list containing four numbers 98 110 98 and 109
the problem comes with removing them i was gonna set up another 3 keys to remove them
so for example i might press k which would remove 109 from the list leaving 98 110 98
i might then press h which would remove one of the 98's from the list leaving 98 and 110
I don't think this library does this with out specifying an index or remove first or last
i know i can search the list for a number but then i can't report the index to delete it
has anyone know what i should be using to achieve this,
I presume i could go down the array route ??? but it would be nice to use a list library
thanking you in advance
#include <LinkedList.h>
int listSize = 0;
int inByte = 0;Â // for incoming serial data
LinkedList<int> myList = LinkedList<int>();
void setup() {
 Serial.begin(9600);  // opens serial port, sets data rate to 9600 bps
 Serial.println ("use key b n and m to add to stack");
}
void loop() {
 if (Serial.available() > 0) {
  inByte = Serial.read();
  if (inByte != 10)
  {//is anything but return
   Serial.println(" ");
   Serial.print("I received: ");
   Serial.println(inByte, DEC);
   if (inByte == 98 || inByte == 110 || inByte == 109 )
   {//is b n m
    if (inByte == 98 || inByte == 110 || inByte == 109)
    {
     myList.add(inByte);
     listSize = myList.size();
     Serial.print("list size ");
     Serial.println(listSize);
    }
    printList();
   }//end of bnm
  }// end of if (inByte != 10)
 }//end of if available
}//end of loop
void printList(){
 for (int h = 0; h < listSize; h++) {
  int val = myList.get(h);
  Serial.print("val = ");
  Serial.println(val);
 }//eo for
}// eo print list