Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- struct Nod
- {
- int info;
- Nod *leg;
- };
- Nod *first, *last;
- int main()
- {
- int n, i, x;
- ifstream fin("sir.in");
- fin >> n;
- fin >> x;
- first = new Nod;
- first -> info = x;
- first -> leg = NULL;
- last = first;
- for(i = 1; i < n; i++)
- {
- fin >> x;
- if(x <= first -> info)
- {
- Nod *p;
- p = new Nod;
- p -> info = x;
- p -> leg = first;
- first = p;
- }
- else if(x >= last -> info)
- {
- Nod *q;
- q = new Nod;
- q -> info = x;
- q -> leg = NULL;
- last -> leg = q;
- last = q;
- }
- else
- {
- Nod *p,*q;
- for(p = first; x > p->info; p = p->leg)
- q = p;
- p = new Nod;
- p -> info = x;
- p -> leg = q -> leg;
- q -> leg = p;
- }
- }
- fin.close();
- for(Nod *p = first; p != NULL; p = p->leg)
- cout << p->info <<" ";
- cout << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement