1 . 静态链表 #include<stdio.h> struct node { int data; struct node *next; }; typedef struct node nodeType; int main() { nodeType sOne,sTwo,sThree, *begin, *p; clrscr(); sOne.data = 1; sTwo.data = 2; sThree.data = 3; begin = &sOne; sOne.next = &sTwo; sTwo.next = &sThree; sThree.next = '/0'; p=begin; while(p) { printf("%d ",p->data); p=p->next; } printf("/n"); getch(); return 0; } 2.动态列表 #include "stdafx.h" #include <iostream> #include <stdio.h> using namespace std; typedef struct node { int data; struct node *next; }nodeType; nodeType* CreateDynamicLink() { nodeType *begin,*end,*temp; begin = (nodeType*)malloc(sizeof(nodeType)); end = begin; int i = -1; cout<<"Enter thd numbers (end with -1):"; cin>>i; while(i!=-1) { temp = (nodeType*)malloc(sizeof(nodeType)); temp->data = i; end->next = temp; end = temp; cin>>i; } end->next = NULL; return begin; } int main(int argc, char* argv[]) { nodeType *head; head = CreateDynamicLink(); while(head) { cout<<head->data<<endl; head = head->next; } return 0; }