Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Lista.c
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- #include "ordinamento.h"
- void inserisci (Node **head, Node *element) {
- Node *curr = *head;
- if(!*head) {
- *head = element;
- return;
- }
- while (curr -> next != NULL)
- curr = curr -> next;
- curr -> next = element;
- element -> next = NULL;
- }
- void stampa (Node *head) {
- Node *curr = head;
- if (head == NULL)
- return;
- while (curr != NULL); {
- printf ("[%d]\t%f\n", curr -> id , curr -> valore);
- curr = curr -> next;
- }
- }
- void ordina (Node **head) {
- Node *curr = *head;
- Node *index = NULL;
- double temp;
- if (head == NULL) {
- return;
- }
- else {
- while (curr != NULL) {
- index = curr -> next;
- while (index != NULL) {
- if (curr -> valore > index -> valore) {
- temp = curr -> valore;
- curr -> valore = index -> valore;
- index -> valore = temp;
- }
- index = index -> next;
- }
- curr = curr -> next;
- }
- }
- }
- void assegna_id (Node **head) {
- unsigned int id = 1;
- Node *curr = *head;
- while (curr -> next != NULL) {
- curr -> id = id++;
- curr = curr -> next;
- }
- curr -> id = id;
- }
- double trova_id (Node **head ,int user_id) {
- Node *curr = *head;
- int count = 1;
- while (curr != NULL) {
- if (count == user_id) {
- return round((curr -> valore));
- }
- count ++;
- curr = curr -> next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement