Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <stdlib.h>
- using namespace std;
- struct node{
- node * next;
- int value;
- };
- void DELL(node *& H){
- if(H!=NULL){
- node * temp=new node;
- temp = H;
- H=temp->next;
- delete temp;
- }
- }
- void ADD( node *& H, int val){
- node * temp = new node;
- temp->next=H;
- temp->value=val;
- H=temp;
- }
- void show(node * H){
- cout <<"H->";
- node *temp=H;
- while(temp!=NULL){
- cout << temp->value<<"->";
- temp=temp->next;
- }
- cout << "NULL"<<endl;
- }
- void srednia(node*&H)
- {
- if (H != NULL)
- {
- node *temp = H;
- node *tmp = NULL;
- node *tmp2 = NULL;
- float x = 0, i = 0;
- float srednia = 0;
- while (temp != NULL)
- {
- if (temp->next == NULL)
- tmp = temp;
- x = x + temp->value;
- i++;
- temp = temp->next;
- }
- int z = 0;
- srednia = x / i;
- delete temp;
- temp = H;
- cout<<"srednia: " << srednia << endl;
- while(z < i)
- {
- z++;
- if(H->value > srednia)
- {
- tmp->next=temp;
- tmp=tmp->next;
- H=H->next;
- temp=H;
- }
- else
- {
- if(temp->value > srednia)
- {
- tmp->next=temp;
- tmp=tmp->next;
- temp=tmp2;
- temp->next=temp->next->next;
- temp=temp->next;
- }
- else
- {
- tmp2=temp;
- temp=temp->next;
- }
- }
- }
- tmp->next=NULL;
- }
- }
- int main()
- {
- node * H = NULL;
- ADD(H, 5);
- ADD(H, 4);
- ADD(H, 7);
- ADD(H,22);
- ADD(H,11);
- ADD(H,12);
- show(H);
- srednia(H);
- show(H);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement