
#include <iostream.h>

typedef struct nod {
  int data;
  nod* next;

} nod;

typedef nod* pnod;

class List {

public:
  List();

  // Lägger till element i listan
  // Pre: 0 <= pos < listsize
  // Post: element finns i listan på pos, liststorlek ökad med ett
  void put(int element, int pos);


  // Pre: true
  // Post: Storleken på listan returneras
  int size();

  void print();


private:
  pnod head;
};

List::List() {
  head = NULL; // Ta bort för bugg?
}


void List::put(int element, int pos) {
  
  pnod cur, prev, ny;
  int count;

  cur = head;
  count = pos;
  while(count-- > 0) { prev = cur; cur = cur->next; }

  ny = new nod;

  ny->data = element;
  
  if (pos == 0) {
    ny->next = head;
    head = ny;
  } else {
    ny->next = cur->next;
    prev->next = ny;
  }

}

int List::size() {
  int count = 0;
  pnod cur;

  cur = head;

  while (cur != NULL) {
    cur = cur->next;
    count++;
  }

  return count;
  
}


void List::print() {
  pnod cur;

  cur = head;

  while (cur != NULL) {
    cout << cur->data << " ";
    cur = cur->next;
  }

  


}

int main() {

  List minLista;
  
  cout << "Storlek: " << minLista.size() << endl;
  minLista.put(5, 0);
  minLista.put(6, 0);
  minLista.put(7, 0);
  cout << "Storlek: " << minLista.size() << endl;
  cout << "Innehåll ";
  minLista.print();
  cout << endl;


}
