#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
int k, m, summ;
string cn, sn;
struct client
{
string num;
string pren;
int sum;
struct client *urm;
};
struct client *head = NULL;
void addelq(string n, string p, int s)
{
struct client *c = new client;
c->num = cn;
c->pren = sn;
c->sum = summ;
c->urm = head;
head = c;
return;
}
void viewq()
{
struct client *c;
c = head;
while (c != NULL)
{
cout << c->num << " " << c->pren << " " << c->sum << endl;
c = c ->urm;
}
}
void removeq()
{
struct client *c, *tmp;
if (head == NULL) { cout <<"Empty structure! Nothing to remove" << endl; return;}
if (head -> urm == NULL) { c = head; head = NULL; free(c); cout <<"Removed! Caution! Empty structure!" << endl; return;}
c = head;
while (c -> urm -> urm != NULL) c = c->urm;
tmp = c -> urm;
c -> urm = NULL;
free(tmp);
return;
}
void removes()
{
struct client *c; // you can use delete() instead of free()
if (head == NULL) { cout <<"Empty structure! Nothing to remove" << endl; return;}
if (head -> urm == NULL) { c = head; head = NULL; free(c); cout <<"Removed! Caution! Empty structure!" << endl; return;}
c = head;
head = head -> urm;
free(c);
return;
}
int main()
{
while(1)
{
cout << "1: adaugare"<< endl;
cout << "2: parcurgere"<< endl;
cout << "3: lichidare - coada"<< endl;
cout << "4: lichidare - stiva"<< endl;
cout << "5: STOP"<< endl;
cout << "Introduceti nr funtctiei: ";
cin >> k;
switch(k)
{
case 1:
{
cout << "Name: "; cin >> cn;
cout << "Surname: "; cin >> sn;
cout << "Suma: "; cin >> summ;
addelq(cn,sn,summ);
break;
}
case 2: viewq(); break;
case 3: removeq(); break;
case 4: removes(); break;
case 5: return 5;
}
}
}