فکر نمیکنم نیاز به توضیح باشه، بچه هایی که ساختمون داده دارن خودشون با این مبحث آشنایی دارن
حالا باز اگه سوالی بود در خدمتم، ولی سعی کنین از مدیران بپرسین ، راستشو بخواین من خودم console زیاد کار نکردم فقط یه برنامه هایی برای آشنایی دارم میخونم ، گفتم شاید به دردتون بخوره
بااحترام
using System;
using System.Collections.Generic;
using System.Text;
namespace Infix
{
class Stacke
{
int size = 100;
object[] item;
int top;
public Stacke()
{
top = -1;
item=new object [size];
}
public bool IsFull()//don't have
{
if (top == size - 1)
return true;
else
return false;
}
public bool IsEmpty()//do have
{
if (top == -1)
return true;
else
return false;
}
public bool Push(object n)
{
if (IsFull())
return false;
else
{
item[++top] = n;
return true;
}
}
public object Pop()
{
if (IsEmpty())
return -1;
else
return item [top--];
}
public object TestTop()
{
if (IsEmpty())
return -1;
else
return item[top];
}
}
}
فراخونی:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Infix
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btn_Change_Click(object sender, EventArgs e)
{
Stacke ExampleStack = new Stacke();
object topStack = null;
object Capacity = null;
string STRING = txt_Infix.Text;
string posfix = "";
bool NUMBER = true;
for (int i = 0; i < STRING.Length; i++)
{
switch (STRING[i])
{
case '+':
while (NUMBER)
{
topStack = ExampleStack.TestTop();
if (ExampleStack.IsEmpty())
{
ExampleStack.Push(STRING[i]);
break;
}
else if ((char)topStack == '*')
{
Capacity = ExampleStack.Pop();
posfix += Capacity;
}
else if ((char)topStack == '/')
{
Capacity = ExampleStack.Pop();
posfix += Capacity;
}
else if ((char)topStack == '-')
{
Capacity = ExampleStack.Pop();
posfix += Capacity;
}
else if ((char)topStack == '+')
{
Capacity = ExampleStack.Pop();
posfix += Capacity;
}
else if ((char)topStack == '(')
{
ExampleStack.Push(STRING[i]);
break;
}
}
break;
case '-':
while (NUMBER)
{
topStack = ExampleStack.TestTop();
if (ExampleStack.IsEmpty())
{
ExampleStack.Push(STRING[i]);
break;
}
else if ((char)topStack == '*')
{
Capacity = ExampleStack.Pop();
posfix += Capacity;
}
else if ((char)topStack == '/')
{
Capacity = ExampleStack.Pop();
posfix += Capacity;
}
else if ((char)topStack == '-')
{
Capacity = ExampleStack.Pop();
posfix += Capacity;
}
else if ((char)topStack == '+')
{
Capacity = ExampleStack.Pop();
posfix += Capacity;
}
else if ((char)topStack == '(')
{
ExampleStack.Push(STRING[i]);
break;
}
}
break;
case '/':
while (NUMBER)
{
topStack = ExampleStack.TestTop();
if (ExampleStack.IsEmpty())
{
ExampleStack.Push(STRING[i]);
break;
}
else if ((char)topStack == '*')
{
Capacity = ExampleStack.Pop();
posfix += Capacity;
}
else if ((char)topStack == '/')
{
Capacity = ExampleStack.Pop();
posfix += Capacity;
}
else if ((char)topStack == '-')
{
ExampleStack.Push(STRING[i]);
break;
}
else if ((char)topStack == '+')
{
ExampleStack.Push(STRING[i]);
break;
}
else if ((char)topStack == '(')
{
ExampleStack.Push(STRING[i]);
break;
}
}
break;
case '*':
while (NUMBER)
{
topStack = ExampleStack.TestTop();
if (ExampleStack.IsEmpty())
{
ExampleStack.Push(STRING[i]);
break;
}
else if ((char)topStack == '*')
{
Capacity = ExampleStack.Pop();
posfix += Capacity;
}
else if ((char)topStack == '/')
{
Capacity = ExampleStack.Pop();
posfix += Capacity;
}
else if ((char)topStack == '-')
{
ExampleStack.Push(STRING[i]);
break;
}
else if ((char)topStack == '+')
{
ExampleStack.Push(STRING[i]);
break;
}
else if ((char)topStack == '(')
{
ExampleStack.Push(STRING[i]);
break;
}
}
break;
case '(':
ExampleStack.Push(STRING[i]);
break;
case ')':
while (NUMBER)
{
topStack = ExampleStack.TestTop();
if ((char)topStack == '(')
{
ExampleStack.Pop();
break;
}
else
{
posfix += ExampleStack.Pop();
}
}
break;
default:
posfix += STRING[i];
break;
}
}
while (NUMBER)
{
if (ExampleStack.IsEmpty())
break;
else
posfix += ExampleStack.Pop();
}
txt_Postfix.Text = posfix.ToString();
}
}
}
علاقه مندی ها (Bookmarks)