Hello,
I know C++, but I can't programme in C# code (although I can read it).
I think you should ask in the C# forum. Normally speaking, C# programmers can read C++ . So they can help you. I suppose you should add the tag for the C# forum dotnet-csharp.html to your question.
Regards, Guido
Convert C++ to C#
Hi All,
I need a help to convert below C++ code to C#.
include <stdio.h>
include <stdlib.h>
int top = 10;
struct node
{
char ch;
struct node *next;
struct node *prev;
} *stack[11];
typedef struct node node;
void push(node *str)
{
if (top <= 0)
printf("Stack is Full ");
else
{
stack[top] = str;
top--;
}
}
node *pop()
{
node *exp;
if (top >= 10)
printf("Stack is Empty ");
else
exp = stack[++top];
return exp;
}
void convert(char exp[])
{
node *op1, *op2;
node temp;
int i;
for (i=0;exp[i]!='\0';i++)
if (exp[i] >= 'a'&& exp[i] <= 'z'|| exp[i] >= 'A' && exp[i] <= 'Z')
{
temp = (node)malloc(sizeof(node));
temp->ch = exp[i];
temp->next = NULL;
temp->prev = NULL;
push(temp);
}
else if (exp[i] == '+' || exp[i] == '-' || exp[i] == '' || exp[i] == '/' ||
exp[i] == '^')
{
op1 = pop();
op2 = pop();
temp = (node)malloc(sizeof(node));
temp->ch = exp[i];
temp->next = op1;
temp->prev = op2;
push(temp);
}
}
void display(node *temp)
{
if (temp != NULL)
{
display(temp->prev);
printf("%c", temp->ch);
display(temp->next);
}
}
void main()
{
char exp[50];
printf("Enter the postfix expression :");
scanf("%s", exp);
convert(exp);
printf("\nThe Equivalant Infix expression is:");
display(pop());
printf("\n\n");
}
2 answers
Sort by: Most helpful
-
Guido Franzke 2,186 Reputation points
2021-04-07T09:42:59.677+00:00 -
WayneAKing 4,926 Reputation points
2021-04-07T18:33:08.49+00:00 Whenever I see a request such as this my suspicions
often get aroused that the asker is:(1) Trying to complete an assignment in the target
language, and has done a web search for code to
plagiarize. Finding code that looks promising,
but in another language, the questioner then
tries to get someone to convert it for free.(2) Or the asker wants to copy the functionality
of someone else's code so they can claim it as their
own.(3) Of course, it's also possible that the C/C++ code
posted was actually written by the asker, and they
are just trying to migrate it to C# as part of a
general shift to that language.Now none of the above may apply in this case, and
if not can be ignored as generalizations with
no personal association. If the mud doesn't stick,
then perhaps this is for personal use or benefit,
which then leads me to query if the asker is
willing to pay for a code conversion?While waiting for someone to convert it for you for
free (someone usually will eventually, if only to
show off their own skills), you might try this
converter - it has a feature-limited free version
you can try:Tangible Software Solutions
Source Code Converters
https://www.tangiblesoftwaresolutions.com/index.html- Wayne