Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Iterator<Regate> it;
- Liste<Regate> lreg;
- ......
- cout << "Choix: ";
- scanf ("%d",&choix);
- switch (choix)
- {
- case 1: Ajout(&lreg);
- break;
- case 2: Affich(lreg, it);
- // ERREUR : JE NE PEUX PASSER QU UNE FOIS DS CASE 2 OU CASE 3.
- break;
- case 3: Sauvegarde (lreg, it);
- break;
- default : cout << "Vous devez faire un choix correcte ! 1 - 2 - 3." << endl;
- }
- void Ajout(Liste<Regate> *lreg)
- {
- Regate r;
- cout << " Ajout d'une regate" << endl;
- cin >> r;
- lreg->add(r);
- cout << "Verification d'ajout: ";
- if(lreg->contains(r)) // Vérification d'ajout.
- {
- cout << "SUCCESS" << endl;
- }
- else
- {
- cout << "FAILED" << endl;
- }
- }
- void Affich(Liste<Regate> lreg, Iterator<Regate> it)
- {
- cout << "affich";
- Regate r;
- it = lreg.getIterator();
- while(it.hasNext())
- {
- std::cout << it.next() << std::endl;
- }
- }
- void Sauvegarde (Liste<Regate> lreg, Iterator<Regate> it)
- {
- cout << "save!";
- fstream f;
- Regate r;
- it = lreg.getIterator();
- f.open("Regate.txt",ios::trunc|ios::out);
- while(it.hasNext())
- {
- f << it.next();
- i++;
- }
- f.close();
- }
- // Iterator.h
- template <class E>
- class Iterator
- {
- private:
- Cellule<E>* curCell;
- public:
- Iterator()
- {
- curCell = NULL;
- }
- Iterator(Cellule<E>* cell)
- {
- curCell = cell;
- }
- ~Iterator()
- {
- };
- bool hasNext()
- {
- return curCell != NULL;
- }
- E next()
- {
- E ret = curCell->data;
- curCell = curCell->next;
- return ret;
- }
- };
- // Dans liste.h :
- Iterator<E> getIterator()
- {
- Iterator<E> it(firstCell);
- return it;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement