• Jump To … +
    array_of_routines.c array_utils.h print.c arrays_and_pointers.c arrays_basics.c command_line.c fibonacci.c hello_world.c hello_world_correct.c linked_list.c malloc_stuff.c nans_and_other_oddities.c rationals_with_structs.c routine_pointers.c experiments.c naive_sequence_of_longs.c naive_sequence_of_longs.h sequence_of_longs.c sequence_of_longs.h tests.c sizeof_and_arrays.c array_of_doubles.c array_of_doubles.h perform_experiments.c sorting_algorithms.c sorting_algorithms.h string_io.c
  • ¶

    experiments.c – Experiências com sucessões de long

  • ¶
    #include <stdio.h>
    #include <stdlib.h>
    
    #include "sequence_of_longs.h"
    #include "naive_sequence_of_longs.h"
    
    int main(void)
    {
    	struct sequence_of_longs *sequence = SEQL_new();
    
    	for (long i = 0L; i != 1000L; i++)
    		SEQL_add(sequence, i);
    
    	printf("The length is: %d\n", SEQL_length(sequence));
    
    	printf("The sequence is: ");
    	SEQL_println(sequence);
    
    	printf("The items are:");
    	for (int i = 0; i != SEQL_length(sequence); i++)
    		printf(" %ld", SEQL_term(sequence, i));
    	putchar('\n');
    
    	free(sequence);
    
    	struct naive_sequence_of_longs *naive_sequence = NSEQL_new();
    
    	for (long i = 0L; i != 1000L; i++)
    		NSEQL_add(naive_sequence, i);
    
    	printf("The length (naive) is: %d\n", NSEQL_length(naive_sequence));
    
    	printf("The sequence (naive) is: ");
    	NSEQL_println(naive_sequence);
    
    	printf("The items (naive) are:");
    	for (int i = 0; i != NSEQL_length(naive_sequence); i++)
    		printf(" %ld", NSEQL_term(naive_sequence, i));
    	putchar('\n');
    
    	free(naive_sequence);
    
    	return EXIT_SUCCESS;
    }