Advertisement
Guest User

Untitled

a guest
Jan 6th, 2021
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.37 KB | None | 0 0
  1. //Lista.c
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <math.h>
  7. #include "ordinamento.h"
  8.  
  9. void inserisci (Node **head, Node *element) {
  10.     Node *curr = *head;
  11.     if(!*head) {
  12.         *head = element;
  13.         return;
  14.     }
  15.     while (curr -> next != NULL)
  16.         curr = curr -> next;
  17.    
  18.     curr -> next = element;
  19.     element -> next = NULL;
  20. }
  21.  
  22. void stampa (Node *head) {
  23.     Node *curr = head;
  24.     if (head == NULL)
  25.         return;
  26.     while (curr != NULL); {
  27.         printf ("[%d]\t%f\n", curr -> id , curr -> valore);
  28.         curr = curr -> next;
  29.     }
  30. }
  31.  
  32. void ordina (Node **head) {
  33.     Node *curr = *head;
  34.     Node *index = NULL;
  35.     double temp;
  36.  
  37.     if (head == NULL) {
  38.         return;
  39.     }
  40.     else {
  41.         while (curr != NULL) {
  42.             index = curr -> next;
  43.  
  44.             while (index != NULL) {
  45.                 if (curr -> valore > index -> valore) {
  46.                     temp = curr -> valore;
  47.                     curr -> valore = index -> valore;
  48.                     index -> valore = temp;
  49.                 }
  50.                 index = index -> next;
  51.             }
  52.             curr = curr -> next;
  53.         }
  54.     }
  55. }
  56.  
  57. void assegna_id (Node **head) {
  58.         unsigned int id = 1;
  59.         Node *curr = *head;
  60.         while (curr -> next != NULL) {
  61.         curr -> id = id++;
  62.         curr = curr -> next;
  63.         }
  64.         curr -> id = id;
  65. }
  66.  
  67. double trova_id (Node **head ,int user_id) {
  68.     Node *curr = *head;
  69.     int count = 1;
  70.     while (curr != NULL) {
  71.         if (count == user_id) {
  72.             return round((curr -> valore));
  73.         }
  74.         count ++;
  75.         curr = curr -> next;
  76.     }
  77. }
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement