poo llsi_1

Download POO LLSI_1

If you can't read please download the document

Upload: dragu-stelian

Post on 05-Nov-2015

1 views

Category:

Documents


0 download

DESCRIPTION

POO

TRANSCRIPT

Untitled

#include #include using namespace std;

class Node{public: int info; Node *next; Node(int x, Node *pnext):info(x), next(pnext) {}; int getInfo() { return info; } Node *Next() { return next; } void setNext(Node *pnext) { next = pnext; }};

class List{public: Node *head; List():head(NULL) {}; void Add(int info) { Node *new_node = new Node(info, NULL); Node *temp = head; if (temp != NULL) { while (temp->Next() != NULL) temp = temp->Next(); temp->setNext(new_node); } else head = new_node; } void Delete(int info) { Node *temp = head; if (temp == NULL) exit(0); if (temp->Next() == NULL) { delete temp; head = NULL; } else { Node *prev; do { if (temp->getInfo() == info) break; prev = temp; temp = temp->Next(); } while (temp != NULL); prev->setNext(temp->Next()); delete temp; } } void Print() { Node *temp = head; if (temp == NULL) { cout