Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- #include <string>
- #include <cstdio>
- #define N 4
- using namespace std;
- struct Student{
- int nr_indeksu;
- string nazwisko;
- float ocena;
- Student *nast;
- Student *poprz;
- };
- istream& operator>>(istream& in, Student& s)
- {
- in >> s.nr_indeksu;
- in >> s.nazwisko;
- in >> s.ocena;
- return in;
- }
- int main(){
- Student *iter = NULL, *nowy = NULL, *usun = NULL, *glowa = NULL, *ogon = NULL;
- cout<<"Podaj nazwe pliku z danymi:";
- string nazwa_pliku;
- cin>>nazwa_pliku;
- ifstream plik;
- plik.open(nazwa_pliku.c_str());
- if(plik.good()){
- while(!plik.eof() && plik.good()){
- nowy = new Student;
- plik>>*nowy;
- if(glowa){
- if (nowy->nr_indeksu < glowa->nr_indeksu){
- nowy->nast=glowa;
- glowa->poprz=nowy;
- glowa=nowy;
- }
- else {
- for(iter=glowa;iter!=NULL;iter=iter->nast){
- if (nowy->nr_indeksu < iter->nr_indeksu){
- nowy->nast = iter;
- nowy->poprz = iter->poprz;
- nowy->nast->poprz = nowy;
- nowy->poprz->nast = nowy;
- break;
- }
- if(!iter){
- nowy->poprz = ogon;
- ogon->nast = nowy;
- ogon = nowy;
- }
- }
- }
- else{
- ogon=glowa = nowy;
- }
- plik.close();
- }
- }
- cout<<"lista od poczatku";
- for(iter=glowa; iter!=NULL; iter=iter->nast){
- cout<<iter;
- }
- iter = glowa;
- while(iter!=NULL){
- usun = iter;
- iter=iter->nast;
- delete(usun);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement