C # pointer linked list structure unsafe

Source: Internet
Author: User
Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. text;
Using system. Windows. forms;

Namespace windowsapplication10
{
Public partial class form1: Form
{
Public form1 ()
{
Initializecomponent ();
}

Private void button#click (Object sender, eventargs E)
{

Node mynode = new node ();

Mynode. addnode ("first ");

Mynode. addnode ("second ");

Mynode. addnode ("third ");

Mynode. addnode ("forst ");

Node node;

Node = mynode;
While (node! = NULL)
{
MessageBox. Show (node. Name );
Node = node. Next;
}

Mynode. delnode (3 );

Node = mynode;
While (node! = NULL)
{
MessageBox. Show (node. Name );
Node = node. Next;
}

}

Unsafe int sum (int * I, int * j)
{
Return * I + = * J;
}

Unsafe int sumsafe (int I, Int J)
{
Return sum (& I, & J );
}

Private unsafe void button2_click (Object sender, eventargs E)
{
// Int J = sumsafe (2, 3 );
Int A = 2;
Int B = 3;
Int J = sum (& A, & B );
MessageBox. Show (J. tostring ());
}

Private unsafe void button3_click (Object sender, eventargs E)
{
Int I = 3;
Ptrnode PTR = new ptrnode (& I );

Int J = 3;
Ptrnode P = new ptrnode (& J );

PTR. Next = & P;


}

}


Public class Node
{
Private string name;
Private node head;
Private node next;
Private int index;

Public string name
{
Get {return this. Name ;}
Set {This. Name = value ;}
}

Public node head
{
Get {return this. Head ;}
}

Public node next
{
Get {return this. Next ;}
}

Public node ()
{
Name = "nodehead ";
}

Public void addnode (string name)
{
Node x = this;
Node T = new node ();
T. Name = Name;

While (X. Next! = NULL)
{
X = x. Next;
}

X. Next = T;
T. Head = X;

Index = index + 1;
}

Public void delnode (INT index)
{
Node temp = this;

Int I = 0;
While (I <index)
{
Temp = temp. Next;
I + = 1;
}

Temp. Head. Next = temp. Next;
}

}

Unsafe struct ptrnode
{
Public int * ID;
Public ptrnode * next;

Public ptrnode (int * Aid)
{
Id = aid;
Next = NULL;
}
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.