Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void expressionLL(char* infix, LinkedList *inExpLL) {
- //init variables
- LinkedList *s = malloc(sizeof(LinkedList));
- char tempInt[99]; // to store the string of numbers
- int index = 0;
- while (*infix != '\0') {
- ListNode *temp = malloc(sizeof(ListNode));
- //handles insertion of ListNode into the linked list
- if (inExpLL->head == NULL) inExpLL->head = temp;
- else {
- ListNode *currNode = inExpLL->head;
- while (currNode->next != NULL) currNode = currNode->next;
- currNode->next = temp;
- }
- //checks where the number ends
- while (*infix>=48) {
- tempInt[index] = *infix;
- infix++;
- index++;
- }
- tempInt[index] = '\0';
- //checks if tempInt is populated with numbers. If not, then insert a node that is an operator
- temp->item = (tempInt[0] == '\0') ? *infix : atoi(tempInt);
- temp->type = (tempInt[0] == '\0') ? OPT : OPERAND;
- //if temp's type is OPERAND, insert the current char from infix bc it will be an operator
- if (*infix != '\0' && temp->type != OPT) {
- ListNode *tempOpt = malloc(sizeof(ListNode));
- tempOpt->item = *infix;
- tempOpt->type = OPT;
- temp->next = tempOpt;
- }
- infix++;
- //resets vars for next loop
- tempInt[0] = '\0';
- index = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement