Hi I am incredibly new to C++ programming and am sure my code is an absolute mess:
I tried compiling and it said I had a "parse error before string constant" error on the lines that are in red.Code:#include <iostream> #include <stdlib.h> struct listNode { int value; struct listNode *next; }; typedef struct listNode LISTNODE; LISTNODE *createList(void); LISTNODE *addNodeAfter(LISTNODE *list, int node); LISTNODE *getNextNode(LISTNODE *thisNode); int setNodeValue(LISTNODE *list, int node, int value); int getNodeValue(LISTNODE *list, int node, int *value); main() { LISTNODE *listStart=0; int nodeValue, count; listStart=createList(); if (listStart == 0) { cout << "Failed create the list !\n"; } cout << "Created linked list starting at : " << listStart "\n"; if (!setNodeValue(listStart, 0, 1234)) { cout << "Failed to set the first node value !\n"; } if (!getNodeValue(listStart, 0, &nodeValue)) { cout << "Failed to get the first node value !\n"; } cout << "The first node has a value of: " << nodeValue "\n"; if (!addNodeAfter(listStart, 0)) { cout << "Failed to create new node !\n"; } if (!setNodeValue(listStart, 1, 5678)) { cout << "Failed to set the second node value !\n"; } if (!getNodeValue(listStart, 1, &nodeValue)) { cout << "Failed to get the second node value !\n"; } cout << "The second node has a value of: " << nodeValue "\n"; for (count=2; count<100; count++) { if (!addNodeAfter(listStart, count-1)) { cout << "Failed to create node %i !\n",count+1; break; } setNodeValue(listStart, count, 11*count); } getNodeValue(listStart, count/2, &nodeValue); cout << "Node " << count/2 "has value: " << nodeValue "\n"; return 0; } LISTNODE *createList(void) { LISTNODE *newList; newList=(LISTNODE *)malloc(sizeof(LISTNODE)); if (newList != NULL) { newList->value=0; newList->next=0; } return newList; } LISTNODE *addNodeAfter(LISTNODE *list, int node) { int count=0; LISTNODE *thisNode, *nextNode, *newNode; thisNode=list; newNode=(LISTNODE *)malloc(sizeof(LISTNODE)); if (newNode == NULL) { return NULL; } newNode->value=0; while (thisNode != 0) { if (count == node) { nextNode=getNextNode(thisNode); newNode->next=nextNode; thisNode->next=newNode; return newNode; } count++; thisNode=getNextNode(thisNode); } return NULL; } LISTNODE *getNextNode(LISTNODE *thisNode) { return thisNode->next; } int setNodeValue(LISTNODE *list, int node, int value) { int count=0; LISTNODE *thisNode; thisNode=list; while (thisNode != 0) { if (count == node) { thisNode->value=value; return 1; } count++; thisNode=getNextNode(thisNode); } return 0; } int getNodeValue(LISTNODE *list, int node, int *value) { int count=0; LISTNODE *thisNode; thisNode=list; while (thisNode != 0) { if (count == node) { *value=thisNode->value; return 1; } count++; thisNode=getNextNode(thisNode); } return 0; }



LinkBack URL
About LinkBacks



