Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include "Dictionary.h"
- typedef struct NodeObj{
- char* key;
- char* value;
- } NodeObj;
- typedef NodeObj* Node;
- Node newNode(char* k, char* v){
- Node N = malloc(sizeof(NodeObj));
- N->key = k;
- N->value = v;
- return N;
- }
- void freeNode(Node* pN){
- if(pN != NULL && *pN != NULL){
- free(*pN);
- *pN = NULL;
- }
- }
- void freeAllNodes(Node H){
- if(H != NULL){
- freeAllNodes(H->next);
- freeNode(&H);
- }
- }
- typedef struct DictionaryObj*{
- Node head;
- int size;
- } DictionaryObj;
- Dictionary newDictionary(){
- Dictionary D = malloc(sizeof(DictionaryObj));
- D->head = NULL;
- D->size = 0;
- }
- void freeDictionary(Dictionary* pD){
- if(pD != NULL && *pD != NULL){
- makeEmpty(*pD);
- free(*pD);
- *pD = NULL;
- }
- }
- Node findKey(Dictionary* D, char* k){
- Node N = D->head;
- for(int i = 0; i < D->size; i++){
- if(N == k){
- return N;
- }
- N = N->next;
- }
- return NULL;
- }
- int size(Dictionary D){
- if(D == NULL){
- fprintf(stderr, "Dictionary Error: size() called on NULL IntegerList reference.\n");
- exit(EXIT_FAILURE);
- }
- return D->size;
- }
- char* lookup(Dictionary D, char* k){
- if(D == NULL){
- fprintf(stderr, "Dictionary Error: lookup() called on NULL IntegerList reference.\n");
- exit(EXIT_FAILURE);
- }
- if()
- }
- void insert(Dictionary D, char* k, char* v){
- if(D == NULL){
- fprintf(stderr, "Dictionary Error: insert() called on NULL IntegerList reference.\n");
- exit(EXIT_FAILURE);
- }
- }
- void delete(Dictionary D, char* k){
- if(D == NULL){
- fprintf(stderr, "Dictionary Error: delete() called on NULL IntegerList reference.\n");
- exit(EXIT_FAILURE);
- }
- }
- void makeEmpty(Dictionary D){
- if(D == NULL){
- fprintf(stderr, "Dictionary Error: makeEmpty() called on NULL IntegerList reference.\n");
- exit(EXIT_FAILURE);
- }
- }
- char* DictionaryToString(Dictionary D){
- if(D == NULL){
- fprintf(stderr, "Dictionary Error: DictionaryToString() called on NULL IntegerList reference.\n");
- exit(EXIT_FAILURE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement