首页 > Windows开发 > 详细

利用C#的指针编写都一个简单链表

时间:2015-07-06 13:43:00      阅读:265      评论:0      收藏:0      [点我收藏+]
using System;
 
 namespace UnsafeTest
{
    unsafe struct link
    {
        public int x;
        public link* next;
    }
    class Program
    {
        static unsafe void Main(string[] args)
        {
            int val;
            link* head = stackalloc link[sizeof(link)];
            
            link*q =head;
            for(int i=0;i<=10;i++)
            {
                val = i+100;
                link* temp = stackalloc link[sizeof(link)];
                q->x = val;
                q->next = temp;
                q = temp;
            }
             
            link* t = head;
            while(t->next!=null)
            {
 
                Console.WriteLine(t->x );
                t = t->next;
            }
        }
    }
}

 

利用C#的指针编写都一个简单链表

原文:http://www.cnblogs.com/rinack/p/4623971.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!