#include <iostream> #include<stdio.h> #include<stdlib.h> using namespace std; typedef struct key *ptr; struct key{ int k; ptr next; }; int main() { ptr list=(ptr)malloc(20*sizeof(struct key)); ptr head;head=list; head->k=0; cout<<list->k<<endl; head=head->next; head->k=1; cout<<list->next->k<<endl; head=head->next; head->k=2; cout<<list->next->next->k<<endl; head=head->next; //head->k=0; cout<<list->next->next->next->k<<endl; cout<<"--------------gege--------------"<<endl; ptr tmp=(ptr)malloc(sizeof(struct key)); tmp=list->next->next->next; tmp->next=list->next->next; tmp->next->next=list->next; tmp->next->next->next=list; list=tmp; /*头*/cout<<list->k<<endl; /*1结点*/cout<<list->next->k<<endl; /*2结点*/cout<<list->next->next->k<<endl; /*尾*/cout<<list->next->next->next->k<<endl; return 0; } |
|
来自: Lukies_图书馆 > 《公选》