Untitled
unknown
c_cpp
3 years ago
2.6 kB
37
Indexable
#include <iostream> #include <string> #include <cmath> #include <bits/stdc++.h> #include <chrono> #include <fstream> using namespace std; struct elkol { int dane; elkol *nast; elkol *poprz; }; int main() { elkol* head = NULL; elkol* tail = NULL; elkol* help = NULL; int size = 0; char instrukcja; //info od uzytkownika bool loop = true; //czy zapetlac int elements = 0; //ilosc elementow cout << "podaj jedna z instrukcji:\n" << "d - aby dodac napis do kolejki\n" << "u - aby usunac napis z kolejki\n" << "w - aby wyswietlic zawartosc kolejki\n" << "x - aby zakonczyc\n"; while (loop) { cin >> instrukcja; switch (instrukcja) { case 'd': //dodawanie if (head==NULL) { help = new elkol; cout << "podaj dane: "; cin >> help -> dane; help -> nast=NULL; help -> poprz=NULL; head = help; tail = help; } else { help = new elkol; cout << "podaj dane: "; cin >> help -> dane; help -> nast=NULL; help -> poprz=tail; tail -> nast=help; tail = help; } break; case 'u': //usuwanie if (head!=NULL) { help = head; head = head -> nast; help = NULL; } else { cout << "kolejka jest pusta! \n"; } break; case 'w': //wyswietlanie help = head; while (help!=NULL) { cout << help -> dane << " "; help = help -> nast; } cout << "\n"; break; case 'W': //wyswietlanie od tylu help = tail; while (help!=NULL) { cout << help -> dane << " "; help = help -> poprz; } cout << "\n"; break; case 'x': //wyjscie cout << "wychodzenie z programu..."; loop = false; break; default: //nieznana instrukcja cout << "nieznana instrukcja..."; break; } } }
Editor is loading...