Lab 5
Lab 5
FIFO
#include <iostream>
#include <windows.h>
using namespace std;
typedef struct Coada Coada;
struct Coada
{
int val;
Coada *pre;
Coada *suc;
};
void watch(Coada* &cap)
{
Coada *n = new Coada;
n=cap;
if(n == NULL) { cout<<"\n\nCoada nu are elemente!\n\n";Sleep(1000);return ;}
cout<<"Elementele cozii:\n";
while(n != NULL)
{
cout<<n->val<<" ";
n = n->suc;
}
cout<<"\n\n";
system("pause");
}
void add(Coada* &cap, int val)
{
Coada *nou = new Coada;
nou->val = val;
nou->pre = NULL;
nou->suc = NULL;
if(cap == NULL)
{
cap = nou;
cap->pre = cap;//->succesor = cap;
return ;
}
cap->pre->suc = nou;
cap->pre = cap->pre->suc;
}
int vl()
{
int n;
cout<<"Dati elementul :\n";
cin>>n;
return n;
}
int main()
{
Coada *cap = NULL;
bool exit = false;
char n;
do
{
system("cls");
cout<<"1. Adauga in coada\n";
cout<<"2. Sterge din coada\n";
cout<<"3. Afiseaza coada\n";
cout<<"4. Exit\n";
cin>>n;
switch(n)
{
case '1' : add(cap,vl()); break;
case '2' : del(cap);break;
case '3' : watch(cap);break;
case '4' : exit = true; break;
default : cout<<"\n\n Nu cunosc asa operatie !!!\n\n";Sleep(1000);
}
}
while(!exit);
return 0;
}
FILO
#include <iostream>
#include <windows.h>
using namespace std;
struct Stiva
{
int val;
Stiva *urmator;
};
int vl()
{
int val;
cout<<"Valoare:\n";
cin>>val;
return val;
}
void cls()
{
system("cls");
}
int main()
{
Stiva *cap = NULL;
char n;
bool exit = false;
do
{
cls();
cout<<"1. Adaugare in stiva\n";
cout<<"2. Stergere din stiva\n";
cout<<"3. Afisarea stivei\n";
cout<<"4. Exit\n";
cin>>n;
switch(n)
{
case '1' : add(cap,vl()); break;
case '2' : del(cap);break;
case '3' : watch(cap);break;
case '4' : exit = true; break;
default : cout<<"\n\nOperatie necunoscuta\n";Sleep(1000);
}
}
while(!exit);
return 0;
}