please convert this to pseudocode #include <iostream> #include <string> using na
ID: 3595289 • Letter: P
Question
please convert this to pseudocode
#include <iostream>
#include <string>
using namespace std;
struct Node {
char letter;
int occurrences;
Node *next=NULL,*head=NULL,*curr=NULL,*temp=NULL;
void addnode(char adddata)
{
Node* n = new Node;
n->next = NULL;
n->letter = adddata;
if (head != NULL)
{
curr = head;
while (curr->next != NULL)
{
curr = curr->next;
}
curr->next = n;
}
else
{
head = n;
}
}
void printlist()
{
curr = head;
while (curr != NULL)
{
cout << curr->letter;
curr = curr->next;
}
}
Node copylist(Node l)
{
curr = head;
while (curr != NULL)
{
l.addnode(curr->letter);
curr = curr->next;
}
return l;
}
Node operator+( const Node& l2)
{
return copylist(l2);
}
};
Node fromstring(string word)
{
Node b;
Node h ;
for (int i = 0; i < word.size(); i++)
{
h.addnode(word[i]);
}
//h.printlist();
return h;
}
void printlist(Node list)
{
list.printlist();
}
typedef Node sortedListNode;
int main()
{
string word1="hello", word2="hassan";
sortedListNode list1;
sortedListNode list2;
sortedListNode list3;
list1=fromstring(word1);
list2 = fromstring(word2);
list3= list1 + list2;
//list3.printlist();
printlist(list3);
system("pause"); return 0;}
#include <iostream>
#include <string>
using namespace std;
struct Node {
char letter;
int occurrences;
Node *next=NULL,*head=NULL,*curr=NULL,*temp=NULL;
void addnode(char adddata)
{
Node* n = new Node;
n->next = NULL;
n->letter = adddata;
if (head != NULL)
{
curr = head;
while (curr->next != NULL)
{
curr = curr->next;
}
curr->next = n;
}
else
{
head = n;
}
}
void printlist()
{
curr = head;
while (curr != NULL)
{
cout << curr->letter;
curr = curr->next;
}
}
Node copylist(Node l)
{
curr = head;
while (curr != NULL)
{
l.addnode(curr->letter);
curr = curr->next;
}
return l;
}
Node operator+( const Node& l2)
{
return copylist(l2);
}
};
Node fromstring(string word)
{
Node b;
Node h ;
for (int i = 0; i < word.size(); i++)
{
h.addnode(word[i]);
}
//h.printlist();
return h;
}
void printlist(Node list)
{
list.printlist();
}
typedef Node sortedListNode;
int main()
{
string word1="hello", word2="hassan";
sortedListNode list1;
sortedListNode list2;
sortedListNode list3;
list1=fromstring(word1);
list2 = fromstring(word2);
list3= list1 + list2;
//list3.printlist();
printlist(list3);
system("pause"); return 0;}
Explanation / Answer
Hi,
Pseud code is the prior step of writing code, not sure why you are going backwards, but pseudo code is just a simple way to explain what the code is doing using possibly english words, lets write the pseudo code for given problem
def class Node: //class to maintain the linked list node
add(char c):
if start is NOT NULL
while(start!=NULL)
start=start->next //go till the last element
start->next=New node(c) //add element at last
else
start=New node(c) //else create the new node and make it head.
end
def copyList(Node l)://copy list to given list
for i in L
add nodes i in L at the end
end
def fromString(string s)//convert string to list
for every char c in s
add newNode(c)
end
def print(Node l)//function to print list
for every in in l
print i
end
Now, the main functions
string word1="hello", word2="hassan";//test strings
sortedListNode list1;//define nodes
sortedListNode list2;
sortedListNode list3;
//test the above methods
list3=list1+list2
print list3
Thumbs up if this was helpful , otherwise let me know in comments
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.