online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <stdio.h> #include <stdlib.h> #include <string.h> struct List { struct List* next; char* word; }; struct List* insertIntoSet(struct List* head, char* word); void deleteList(struct List* list); void printList(struct List* list); int main(int argc, char ** argv) { struct List* list = 0; int i; for (i = 1; i < argc; ++i) list = insertIntoSet(list, argv[i]); printList(list); deleteList(list); return 0; } struct List* newList(struct List* next, char* word) { struct List* list = (struct List*)malloc(sizeof (struct List)); list->next = next; list->word = word; return list; } struct List* insertIntoSet(struct List* head, char* word) { struct List* current = 0; struct List* previous = 0; // New list if (head == 0) return newList(0, strdup(word)); // Find lower bound for (current = head; current != 0; previous = current, current = current->next) { int compareResult = strcmp(word, current->word); // Duplicate if (compareResult == 0) return head; // Lower bound found if (compareResult < 0) break; } // No lower bound, append to tail if (current == 0) { previous->next = newList(0, strdup(word)); return head; } // Insert at current location current->next = newList(current->next, current->word); current->word = strdup(word); return head; } void printList(struct List* list) { printf("list{"); for (; list != 0; list = list->next) printf("(%s)", list->word); printf("}\n"); } void deleteList(struct List* list) { if (list == 0) return; deleteList(list->next); free(list->word); free(list); }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue