Implementing tokenizer and adding tokens to the linked list
Here we go
#include #include #include struct Node { char * value; struct Node *next; }; struct Node *head = NULL; struct Node *last = NULL; char* substr(char*str, int start, int length) { const char* from = str; char *to = (char*) malloc(sizeof(str)/sizeof(char)); strncpy(to, from+start, length); return to; } void addToLinkedList(char* value) { struct Node *curr_node = malloc(sizeof(struct Node)); char * newtemp = malloc(strlen(value)); strncpy(newtemp, value, strlen(value)); curr_node->value = newtemp; curr_node->next = NULL; if (head == NULL) { head = curr_node; last = head; } else { last->next = curr_node; last = curr_node; } } void printLinkedList() { struct Node * curr_node = head; while (curr_node !=NULL) { printf("%sn", curr_node->value); curr_node = curr_node->next; } } void main() { int delimiter_size = 3, i=0, j=0; char* delimit = "abc"; char* text = "someabccodingabctoabcparseab"; int length = strlen(text); char* temp = (char*)malloc(length); while(i < length) { if (text[i] == delimit[0]) //check if the begin { //check if the if (strcmp(substr(text, i, delimiter_size), delimit) == 0) { addToLinkedList(temp); i+=delimiter_size; j=0; memset(temp, '', strlen(temp)); continue; } } temp[j] = text[i]; i++; j++; } if (strlen(temp)) { addToLinkedList(temp); } printLinkedList(); }
See how you would solve these known algorithm problems
Find the pairs that makes K Complementary in the given array java solutionbinary tree problems with solution
Check if two strings are anagrams or not
Find longest palindrom from sequence of characters
Get maximum occurring character
Find K Complementary numbers from array Java implementation
Implement Queue Using two Stacks – JavaScript algorithm
Java solution for checking anagram strings – tell if phrases are anagrams
Kadane’s algorithm in C – Dynamic Programming
testing k complementary pairs algorithm with junit