Skip to content

Instantly share code, notes, and snippets.

@sabinM1
Created April 20, 2023 11:37
Show Gist options
  • Save sabinM1/00002fd9535b70c9aa9649c624983f15 to your computer and use it in GitHub Desktop.
Save sabinM1/00002fd9535b70c9aa9649c624983f15 to your computer and use it in GitHub Desktop.
Coada, stiva
#include <bits/stdc++.h>
using namespace std;
ifstream fin("text.in");
struct nod{
int info;
nod *urm;
};
nod *first, *last;
nod *vf;
void addC(nod *&prim, nod *&ultim, int x){
nod * nou = new nod;
nou -> info = x;
nou -> urm = NULL;
if(prim==NULL)
prim=ultim=nou;
else{
ultim -> urm = nou;
ultim = nou;
}
}
void afisare(nod *p){
if(p==NULL)
cout<<"lista vida";
while(p){
cout<< p -> info<< ' ';
p = p -> urm;
}
cout<<'\n';
}
void addS(nod *&vf, int x){
nod *nou = new nod;
nou -> info = x;
nou -> urm = vf;
vf = nou;
// nod * nou = new nod;
// nou -> info = x;
// nou -> urm = NULL;
// if(vf==NULL)
// vf=nou;
// else{
// nou -> urm = vf;
// vf = nou;
// }
}
void sterge (nod *& p){
if (p==NULL)
return;
nod * q = p;
p = p -> urm;
delete q;
}
int main() {
int x;
while (fin>>x)
addC(first,last,x);
// afisare(first);
while(first){
addS(vf, first -> info);
sterge(first);
}
afisare(vf);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment