Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "la.h"
- #include <stdio.h>
- #include <stdlib.h>
- void add_to_bucket(item ** list, int index, void * value) {
- // Adding an element to the first linked-list
- item * new_item = (item *)(malloc(sizeof(item)));
- list[index]->next = new_item;
- list[index]->next->next=NULL;
- list[index]->next->value=value;
- }
- int main(void) {
- //an array of linked list pointers
- item ** la = (item **)(malloc(100 * sizeof(item *)));
- for (int i = 0; i < 100; i++) {
- la[i] = (item *)(malloc(sizeof(item)));
- la[i]->value= "fish stakes";
- }
- // add a new element to first linked-list of the 100
- add_to_bucket(la, 1, "hello world");
- item * current=la[1];
- //Quick traversal
- while(true) {
- printf("%s", current->value);
- if(current->next != NULL) {
- current=current->next;
- }
- else break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement