Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Convert to pseudocode please. #include <stdio.h> #include <stdlib.h> #include <s

ID: 3704635 • Letter: C

Question

Convert to pseudocode please.

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

//Define a structure named reversedLine

struct reversedLine

{

char lineTokken[20];

struct reversedLine *next;

};

typedef struct reversedLine ReversedLine;

//Declare functions

ReversedLine* popStack(ReversedLine *);

ReversedLine* pushStack(ReversedLine*, char *);

//begin main

int main()

{

//string to be reversed

char sentence[80];

//to contain the words of each string

char tokken[80];

//length of the sentence and loop for each character

int length, loop;

//index of the tokken

int insPosition;

ReversedLine *stackHead;

//begining of stack

stackHead = NULL;

//request user enter a sentence

printf("Enter a sentence: ");

gets(sentence);

//Add a space at the end of the sentence

strcat(sentence, " ");

//get length of the sentence

length = strlen(sentence);

//assigining zero to insPosition

insPosition = 0;

//loop executed for each character in the sentence.

for (loop = 0; loop < length; loop++)

{

// create tokken till space is found in sentence

if (sentence[loop] != ' ')

{

tokken[insPosition++] = sentence[loop];

}

//to put NULL character at the end of the tokken and assign zero to insPosition

else

{

// assign 0 to insPosition for next tokken

tokken[insPosition] = '';

//call pushStack function

stackHead = pushStack(stackHead, tokken);

//assign 0 to insPosition

insPosition = 0;

}

}

//call popStack function

stackHead = popStack(stackHead);

return(0);

} // End main

//pushStack function returns pointer to the head node

ReversedLine * pushStack(ReversedLine *headStack, char *word)

{

//pointer to new node

ReversedLine *newNode;

//assign memory to newNode

newNode = malloc(sizeof(ReversedLine));

//copy the value of word to lineTokken

strcpy(newNode->lineTokken, word);

//next pointer of newNode points to headStack

newNode->next = headStack;

//headStack is moved to the newNode, marking the top of the stack

headStack = newNode;

return(headStack);

}

ReversedLine* popStack(ReversedLine *headStack)

{

//pointer to delete node

ReversedLine *delNode;

int counter = 0;

printf("Output is : ");

//loop till we have value in stack

while (headStack != NULL)

{

//assign the headStack to delNode

delNode = headStack;

printf("Counter = %d and element popped is : %s ", ++counter, delNode->lineTokken);

//headStack is moved to the next node

headStack = headStack->next;

//to release the memory space used

free(delNode);

}

return(headStack);

}

Explanation / Answer

struct reversedLine

{

    char lineTokken[20];

    struct reversedLine *next;

};

typedef struct reversedLine ReversedLine;

function main()

BEGIN

    // create a variable of type ReversedLine

    ReversedLine *stackhead = NULL;

    sentence = ask user to enter a sentence

    // get the length of sentence

    length = lsentence.length()

    insPosition = 0;

    for loop = 0 to length

    BEGIN

    // create tokken till space is found in sentence

    if sentence[loop] not equal to ' '

    BEGIN

         tokken[insPosition++] = sentence[loop];

    //to put NULL character at the end of the tokken

    // and assign zero to insPosition

    else

    BEGIN

        // assign 0 to insPosition for next tokken

         tokken[insPosition] = '';

        //call pushStack function

         stackHead = pushStack(stackHead, tokken);

         //assign 0 to insPosition

         insPosition = 0

    END

    // pop element from stack

    stackHead = popStack(stackHead);


END

function pushStack(headStack , word)

BEGIN

    newNode = create a new node

    copy content of word to newNode->lineTokken

    // make newNode point to head of stack

    newNode->next = headStack

    // make newNode as the new head

    headStack = newNode;

    return headStack


END

function popStack( headStack )

BEGIN

    counter = 0

    while headStack becomes NULL

    BEGIN

         delNode = headStack

         print('counter = ' + counter + ' and element popped is ' + delNode->lineTokken);

         make headStack point to the next node

         delete the node pointed by delNode

    END

    return headStack


END