Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef float Tdata;
- struct Tnode
- {
- Tdata info;
- Tnode *next;
- };
- typedef Tnode* Tlist;
- Tlist L=0;
- void output(Tlist L);
- void create_L(Tlist &L, int n);
- Tlist min(Tlist L);
- Tlist max(Tlist L);
- void change(Tlist &L);
- //
- int main ()
- {
- setlocale(0,"Rus");
- int n;
- cout<<"vvedite kolichestvo uzlov ";
- cin>>n;
- create_L(L,n);
- cout<<"vvedinnye chisla: ";
- output(L);
- change(L);
- cout<<"chisla posle sortirovki: ";
- output(L);
- _getch();
- return 0;
- }
- void output(Tlist L)
- {
- Tlist q=L;
- while (q)
- {
- cout<<(q->info)<<" ";
- q=q->next;
- }
- cout<<endl;
- }
- void create_L(Tlist &L, int n)
- {
- L=new Tnode;
- cout<<"vvedite chislo ";
- cin>>(L->info);
- L->next=0;
- Tnode *q1, *q2;
- q1=L;
- for(int i=1; i<n; i++)
- {
- q2 = new Tnode;
- cout<<"vvedite chislo ";
- cin>>(q2->info);
- q2->next=0;
- q1->next=q2;
- q1=q2;
- }
- }
- Tlist min(Tlist L)
- {
- Tlist q=L;
- Tlist q_min;
- q_min=q;
- q=q->next;
- while (q)
- {
- if ((q_min->info)>(q->info))
- q_min=q;
- q=q->next;
- }
- return q_min;
- }
- Tlist max(Tlist L)
- {
- Tlist q=L;
- Tlist q_max;
- q_max=q;
- q=q->next;
- while (q)
- {
- if ((q_max->info)<(q->info))
- q_max=q;
- q=q->next;
- }
- return q_max;
- }
- void change(Tlist &L)
- {
- Tlist q=L;
- float temp1;
- float L_min=min(L)->info;
- float L_max=max(L)->info;
- while (q)
- {
- if ((q->info)==(L_min))
- q->info=L_max;
- else
- if ((q->info)==(L_max))
- q->info=L_min;
- q=q->next;
- }
- }
Add Comment
Please, Sign In to add comment