Works on mac but not working on windows

Hi, everyone. I am trying to convert infix to postfix using linked list, class and stacks. This program can be compiled on mac and windows but it cannot work properly on windows. It works fine on mac. I can't find the reason. Please help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include <iostream>
using namespace std;

class Node
{
public:
	char alpha;
	Node* next;
};

class Stack
{
private:
	Node* top;

public:
	void createStack();
	void push(char n);
	Node* pop();
	void display()
	{
		Node* curr = top;
	while(curr != NULL)
	{
		cout << curr -> alpha << ",";
		curr = curr -> next;
	}
	cout <<endl;
	}

	bool isEmpty()
	{
		return (top == NULL);
	}

	Node* stacktop()
	{
		return top;
	}
};

class List
{
public:
	Node* head;
	Node* tail;

	void addnode(char n);
	void displaynode();
};

void List::displaynode()
{
	cout << "display "<<endl;
	Node* curr = head;
	while(curr != NULL)
	{
		cout << curr -> alpha;
		curr = curr -> next;
	}
	cout<<endl;
}

void List::addnode(char n)
{
	Node* curr = head;
	Node* prev = NULL;
	Node* newnode = new Node;
	newnode -> alpha = n;
	while(curr != NULL)
	{
		prev = curr;
		curr = curr -> next;
	}

	if(head == NULL)
	{
		head = newnode;
		tail = newnode;
	}
	else
	{
		prev -> next = newnode;
		tail = newnode;
	}
	cout << "newnode : "<<newnode -> alpha<<endl;
}

void Stack::createStack()
{
	top = NULL;
}

void Stack::push(char n)
{
	Node* newnode = new Node;
	newnode -> alpha = n;

	newnode -> next = top;
	top = newnode;
}

Node* Stack::pop()
{
	Node* del = top;
	cout << "pop : "<< del -> alpha <<endl;
	top = top -> next;
	return del;
	//delete del;
	//cout << "top : "<< top -> num <<endl;
}

int precede(char n)
{
	if(n == '+' || n=='-')
		return 1;
	else if(n == '*' || n== '/')
		return 2;
	//else if(n=='#')
	//	return 3;

}


int main()
{
	Stack stack;
	List list;
	char input[10];
	cin >> input;
	int i=0;
	char popchar;
	stack.createStack();
	stack.push('#');

	//cout << "precede : "<< precede('#')<<endl;
	while(input[i]!='\0')
	{
		if(input[i] >= '0' && input[i] <= '9'
			|| input[i] >= 'a' && input[i] <= 'z')
		{
			cout<<"num"<<endl;
			list.addnode(input[i]);
		}

		else if(input[i] == '+' ||
			input[i] == '-' ||
			input[i] == '*' ||
			input[i] == '/')
		{
			cout<<"char"<<endl;
			while(!stack.isEmpty() &&
				precede(stack.stacktop() -> alpha)>=precede(input[i]))
			{
				cout << "stktop : "<<stack.stacktop()->alpha<<endl;
				cout << "p(stktop) : "<<precede(stack.stacktop() -> alpha) <<endl;
				cout << "input [i] : "<<input[i]<<endl;
				cout << "p(input[i]) : "<<precede(input[i])<<endl;
				cout <<"ppp"<<endl;
				popchar = stack.pop() -> alpha;
				list.addnode(popchar);
			}

			stack.push(input[i]);
			cout <<"push : "<<input[i]<<endl;
		}

		
		i++;
	}
	char ppchar;
	while(stack.stacktop()->alpha != '#')
		{
			ppchar = stack.pop() -> alpha;
			cout << "pops : "<< ppchar<<endl;
			list.addnode(ppchar);
		}


	list.displaynode();

	return 0;
}
You’re more likely to get good help if you would be more specific about how it doesn’t work.
Topic archived. No new replies allowed.