Skip to content

hacker3983/list

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 

Repository files navigation

list

A list library for c, dynamically allocated array.

Whats new

  • Fixed memory leaks
  • New list library string
  • Fixed string library crashing on windows
  • Now works for C++
  • int count(struct list list, int x) - counts the occurence of a given element
  • void reversel(struct list* list) - reverses the list
  • int indexl(struct list, int x) - finds the index of a given element

Examples:

  • appending elements and printing
// appending elements to the list and printing
#include <stdio.h>
#include "list/list.h"

int main() {
  struct list list;
  set(&list); // sets the startup options for the list
  for(int i=10;i>-1;i--) {
    append(&list, i);
  }
  print(list); // prints the list
  release(&list); // frees the memory that has been used
}

Appending Elements

  • removing elements
// removing elements from the list
#include <stdio.h>
#include "list/list.h"

int main() {
  struct list list;
  set(&list);
  for(int i=0;i<10;i++) {
    append(&list, i+1);
  }
  printf("List before element has been removed:\n");
  print(list);
  printf("List after element has been removed:\n");
  removel(&list, 4); // removes the element 4
  print(list);
  release(&list);
  return 0;
}

Removing Element

  • counting the occurence of an element
// counting elements
#include <stdio.h>
#include "list/list.h"

int main() {
	struct list list;
	for(int i=2;i<10;i+=2) {
		append(&list, i);
		append(&list, 4);
	}
	print(list);
	printf("4 is in the list %d times\n", count(list, 4)); // amount of times 4 is in the list
	release(&list);
	return 0;
}

Counting elements

  • reverses the list
// reverse list
#include <stdio.h>
#include "list/list.h"

int main() {
	struct list list;
	set(&list);
	for(int i=0;i<10;i++) { append(&list, (i+1) * 2); }
	reverse(&list); // reverse the list
	print(list);
	release(&list);
	return 0;
}

Reversing list

  • finds the index of an element
// finds the index of a given element
#include <stdio.h>
#include "list/list.h"

int main() {
	struct list list;
	set(&list);
	for(int i=1;i<10;i++) { append(&list, i); }
	// returns index of element if not found -1 is returned
	printf("Index of element 5 is %d\n", indexl(list, 5));
	release(&list);
	return 0;
}

Indexing element

About

A list library for c, dynamically allocated array.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages