有次看见别人的面试题问起链表反序.自己实验下.
Code
在主程序下:
Code
十进制与别的进制相互转化:
/// <summary>
/// 把相关十进制整数转成x进制
/// </summary>
/// <param name="i">十进制整数</param>
/// <param name="x">x进制</param>
/// <returns></returns>
public int DOI(int i, int x)
{
int result = 0;
int j = 0;
while (i > 0)
{
result += (int)Math.Pow(10,j)*(i % x);
i = i / x;
j++;
}
return result;
}
/// <summary>
/// 把相关x进制整数转成十进制
/// </summary>
/// <param name="i">x进制整数</param>
/// <param name="x">x进制</param>
/// <returns></returns>
public int IOD(int i, int x)
{
int result = 0;
int j = 0;
while (i > 0)
{
result += (int)Math.Pow(x, j) * (i % 10);
i = i / 10;
j++;
}
return result;
}
/// <summary>
/// 根据上面二段推出x进制的数转成y进制
/// </summary>
/// <param name="i"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public int IOI(int i, int x, int y)
{
int result = 0;
int j = 0;
while (i > 0)
{
result += (int)Math.Pow(x, j) * (i % y);
i = i / y;
j++;
}
return result;
/// 把相关十进制整数转成x进制
/// </summary>
/// <param name="i">十进制整数</param>
/// <param name="x">x进制</param>
/// <returns></returns>
public int DOI(int i, int x)
{
int result = 0;
int j = 0;
while (i > 0)
{
result += (int)Math.Pow(10,j)*(i % x);
i = i / x;
j++;
}
return result;
}
/// <summary>
/// 把相关x进制整数转成十进制
/// </summary>
/// <param name="i">x进制整数</param>
/// <param name="x">x进制</param>
/// <returns></returns>
public int IOD(int i, int x)
{
int result = 0;
int j = 0;
while (i > 0)
{
result += (int)Math.Pow(x, j) * (i % 10);
i = i / 10;
j++;
}
return result;
}
/// <summary>
/// 根据上面二段推出x进制的数转成y进制
/// </summary>
/// <param name="i"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public int IOI(int i, int x, int y)
{
int result = 0;
int j = 0;
while (i > 0)
{
result += (int)Math.Pow(x, j) * (i % y);
i = i / y;
j++;
}
return result;
}