Git Product home page Git Product logo

clib's Introduction

CLib

Example: Stack

#include <stdio.h>

#include "stack.h"

int main(int argc, char **argv)
{
	stack_t *stack = NULL;
	node_t *node = NULL;
	int d1 = 4;
	double d2 = 2.6;

	stack_init(&stack);
	stack_push(stack, &d1);
	stack_push(stack, &d2);

	printf("Items in stack: %ld\n", stack_size(stack));

	node = stack_pop(stack);
	printf("Node value: %f\n", *((double*)node->data));
	printf("Items in stack after pop: %ld\n", stack_size(stack));

	node_destroy(node);

	printf("Stack top value: %d\n", *((int*)stack->top->data));

	stack_destroy(&stack);

	return 0;
}

Example: Vector

#include <stdio.h>

#include "vector.h"

int main(int argc, char **argv)
{
	vector_t *vec = NULL;
	int *vec_item = NULL;
	int i;

	vector_init(&vec);
	printf("Vector size: %ld\n", vector_size(vec));
	printf("Vector capacity: %ld\n", vector_capacity(vec));

	for (i = 0; i < 10; i++)
	{
		vector_add(vec, &i);
	}

	printf("Vector size: %ld\n", vector_size(vec));
	printf("Vector capacity: %ld\n", vector_capacity(vec));

	for (i = 0; i < 10; i++)
		printf("item %d: %d\n", i, *((int*)vec->items[i]));

	vector_trim(vec);
	printf("Vector size: %ld\n", vector_size(vec));
	printf("Vector capacity: %ld\n", vector_capacity(vec));

	vec_item = vector_pop(vec);
	printf("Popped item: %d\n", *vec_item);

	free(vec_item);
	vector_destroy(&vec);

	if (vec == NULL)
		printf("Vector is NULL\n");

	return 0;
}

clib's People

Contributors

henrikac avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.