Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <iostream>
- #include <time.h>
- using namespace std;
- typedef struct nod {
- int nr;
- nod *urm;
- };
- nod *prim = NULL, *ultim = NULL;
- nod * Alloc() {
- return (new nod);
- //return (nod *)malloc(sizeof(nod));
- }
- void Citire(int dimensiune) {
- prim = Alloc();
- cout << "nr = ";
- cin >> prim->nr;
- ultim = prim;
- ultim->urm = NULL;
- for (int i = 0; i < dimensiune-1; i++) {
- nod *temp = Alloc();
- cout << "\nnr = ";
- cin >> temp->nr;
- ultim->urm = temp;
- ultim = temp;
- ultim->urm = NULL;
- }
- }
- void Afisare(int dimensiune) {
- cout << "\nAfisare:\n";
- int i = 0;
- for (nod *temp = prim; temp; temp = temp->urm) {
- cout << "nr." << ++i << " = " << temp->nr << endl;
- }
- }
- void EliminarePrimul() {
- if (prim) {
- if (prim->urm) {
- nod *temp = prim;
- prim = prim->urm;
- delete temp;
- }
- else {
- delete prim;
- prim = ultim = NULL;
- }
- }
- }
- void EliminareUltimul() {
- if (prim) {
- if (prim == ultim) {
- EliminarePrimul();
- }
- else {
- nod *temp;
- for (temp = prim; temp->urm != ultim; temp = temp->urm) {
- }
- ultim = temp;
- ultim->urm = NULL;
- temp = temp->urm;
- }
- }
- }
- void main() {
- int n;
- cout << "Dimensiunea listei = ";
- cin >> n;
- Citire(n);
- Afisare(n);
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement