Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #define N 1000000000
- struct Node {
- int n;
- struct Node *next;
- };
- struct Node *createNode(int n) {
- struct Node *elem = (struct Node *) malloc(sizeof(struct Node));
- elem->n = n;
- elem->next = NULL;
- return elem;
- };
- int main() {
- char end = ' ';
- int n;
- struct Node *head;
- struct Node *elem;
- struct Node *prev;
- struct Node *max = (struct Node *) malloc(sizeof(struct Node));
- struct Node *min = (struct Node *) malloc(sizeof(struct Node));
- struct Node *prev_max = (struct Node *) malloc(sizeof(struct Node));
- struct Node *prev_min = (struct Node *) malloc(sizeof(struct Node));
- struct Node *next_max;
- struct Node *next_min;
- max->n = -N;
- min->n = N;
- for (int i = 0; i < 10; i++) {
- scanf("%d%c", &n, &end);
- elem = createNode(n);
- if((elem->n>max->n) && (i!=0)){
- max = elem;
- prev_max = prev;
- }
- if(elem->n<min->n){
- min = elem;
- prev_min = prev;
- }
- if (i == 0) {
- head = elem;
- prev = head;
- continue;
- }
- prev->next = elem;
- prev = elem;
- if (end == '\n')
- break;
- }
- next_max = max->next;
- next_min = min->next;
- prev_max->next = min;
- prev_min->next = max;
- max->next = next_min;
- min->next = next_max;
- while (head != NULL){
- printf("%d ", head->n);
- head = head->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement