Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.80 KB | None | 0 0
  1. #include "la.h"
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. void add_to_bucket(item ** list, int index, void * value) {
  6.     // Adding an element to the first linked-list
  7.     item * new_item = (item *)(malloc(sizeof(item)));
  8.     list[index]->next = new_item;
  9.     list[index]->next->next=NULL;
  10.     list[index]->next->value=value;
  11. }
  12.  
  13. int main(void) {
  14.     //an array of linked list pointers
  15.     item ** la = (item **)(malloc(100 * sizeof(item *)));
  16.     for (int i = 0; i < 100; i++) {
  17.             la[i] = (item *)(malloc(sizeof(item)));
  18.             la[i]->value= "fish stakes";
  19.     }
  20.     // add a new element to first linked-list of the 100
  21.     add_to_bucket(la, 1, "hello world");
  22.  
  23.     item * current=la[1];
  24.     //Quick traversal
  25.     while(true) {
  26.         printf("%s", current->value);
  27.         if(current->next != NULL) {
  28.             current=current->next;
  29.         }
  30.         else break;
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement