#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_圖書館 > 《公選》