小编Des*_*ire的帖子

使用链接列表和矩阵的图形表示

我知道如何使用链表或矩阵来实现图形。但是我想知道何时使用链表和何时使用矩阵进行图形表示?

algorithm graph data-structures

5
推荐指数
1
解决办法
2396
查看次数

在Codeigniter中在运行时更改数据库连接

我想基于子域连接到不同的数据库,目前我已经有了这个代码,但它找不到解决问题的方法.请正确指导在代码点火器中实现此目的的最佳方法.

class DBConnection extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
    }

    public function dbConfig(){

        $efg="";
        $data = explode('.',$_SERVER['SERVER_NAME']);
        if (!empty($data[0])) {
            $efg = $data[0];
        }

        $sql="SELECT DbUsername,DbName,DbPassword FROM abc WHERE efg=?";
        $d_result=$this->db->query($sql,array($efg))->result_array();

        $this->db->close();

        $config['hostname'] = "localhost";
        $config['username'] = $d_result[0]["DbUsername"];
        $config['password'] = $d_result[0]["DbPassword"];
        $config['database'] = $d_result[0]["DbName"];
        $config['dbdriver'] = "mysql";
        $config['dbprefix'] = "";
        $config['pconnect'] = FALSE;
        $config['db_debug'] = TRUE;
        $config['cache_on'] = FALSE;
        $config['cachedir'] = "";
        $config['char_set'] = "utf8";
        $config['dbcollat'] = "utf8_general_ci";
        return $config;
    }
} 
Run Code Online (Sandbox Code Playgroud)

然后在用户模型类中,我有类似的东西,它在每个请求上再次执行上述所有处理.我希望切换将在开始时进行,进一步的查询将推送到选定的数据库.

class User extends CI_Model
{ …
Run Code Online (Sandbox Code Playgroud)

php codeigniter

4
推荐指数
1
解决办法
9514
查看次数

如何将二进制转换为字符串?

static List<int> ConvertTextToBinary(int number, int Base)
{
    List<int> list = new List<int>();
    while (number!=0)
    {
        list.Add(number % Base);
        number = number / Base;
    }
    list.Reverse();
    return list;
}



static void Main(string[] args)
{

   string s = "stackoverflow";
   int counter=0;
   while (counter!=s.Length)
   {
       int[] a = ConvertTextToBinary(s[counter], 2).ToArray();
       for (int i = 0; i < a.Length; i++)
       {
           Console.Write(a[i]);
       }
       Console.Write("\n");
       counter++;
   }
}
Run Code Online (Sandbox Code Playgroud)

我写了一个将字符串转换为二进制的方法,它工作正常。但现在我想将二进制转换为字符串,例如:1101000 等于 h。

c# string binary

3
推荐指数
2
解决办法
4万
查看次数

如何迭代地在二进制搜索树中添加元素?

   public void Insert(int value)
    {
        if (value < Data)
        {
            if (LeftNode == null)
            {
                LeftNode = new TreeNode(value);
            }
            else
            {
                LeftNode.Insert(value);
            }
        }
        else if (value > Data)
        {
            if (RightNode == null)
            {
                RightNode = new TreeNode(value);
            }
            else
            {
                RightNode.Insert(value);
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

我编写了以递归方式在BST中添加元素的方法,它检查要添加小于或大于的值并将其添加到适当的位置,但我想知道迭代方法是如何工作的?我需要为我的BST迭代添加方法.

c# binary-tree visual-studio-2010

1
推荐指数
1
解决办法
1万
查看次数

如何迭代地找到BST的高度?

  public void HeightIterative()
    {
        int counter = 0;
        int counter2 = 0;
        TreeNode current=root;

        if(current != null)
        {
            while(current.LeftNode!=null)
            {
                counter++;
                current = current.LeftNode;
            }
            while(current.RightNode!=null)
            {
                counter2++;
                current = current.RightNode;
            }
        }

        int res = 1+Math.Max(counter, counter2);
        Console.WriteLine("The Height Of Tree Is: "+res);
    }
Run Code Online (Sandbox Code Playgroud)

我写了迭代方法,来计算树的高度。但在某些情况下,它无法正常工作。如案例: 10 1 2 3 4 5 18 17 16 15 14 13 有什么问题。根据此序列,树的高度为 6,而我的代码显示为 5。

c# binary-tree visual-studio-2010 binary-search-tree

1
推荐指数
1
解决办法
8060
查看次数

如何在窗体面板中绘制形状?

我正在使用面板绘制像圆形的形状,但问题是当我更改制表符或最小化程序然后最大化程序时,然后删除所有绘制的东西.谁能告诉我是什么原因?

c# visual-studio-2010 winforms

0
推荐指数
1
解决办法
2万
查看次数