51,397
社区成员




#include<iostream>
using namespace std;
class list
{
public:
static list *head;
static list *p;
char date;
list *next;
static void * operator new(unsigned int size);
void zhuangdong(list *plist,int n)
{
int i =0;
while(i!=n)
{
p = p->next;
i++;
}
}
void show()
{
for(int i = 0;i!=5;i++)
{
cout<<p->date<<endl;
p = p->next;
}
}
};
void * list::operator new(unsigned int size)
{
list *p1,*p2;
head = static_cast<list *>(::operator new(sizeof(list)));
p1 = head;
head->date = 'a';
p = head;
for(int i = 0;i<4;i++)
{
p2 = static_cast<list *>(::operator new(sizeof(list)));
p1->next = p2;
switch(i)
{
case 0:p2->date = 'b';break;
case 1:p2->date = 'c';break;
case 2:p2->date = 'd';break;
case 3:p2->date = 'e';break;
default:break;
}
p1 = p2;
}
p1->next = head;
return head;
}
list *list::head=NULL;
list *list::p=NULL;
int main()
{
list *p = new list;
p->show();
p->zhuangdong(p,3);
p->show();
}
void swap(int A[],int n,int k)
{
for(int i=0,j=k-1;i<j;i++,j--)
{
int temp=A[i];
A[i]=A[j];
A[j]=A[i];
}
for(int i=k,j=n-1;i<j;i++,j--)
{
int temp=A[i];
A[i]=A[j];
A[j]=A[i];
}
for(int i=0,j=n-1;i<j;i++,j--)
{
int temp=A[i];
A[i]=A[j];
A[j]=A[i];
}
)