folstfolst
全部博文(64)
2010年(64)
Phyllis6
分类: C/C++
2010-01-26 13:45:06
#include<iostream> using namespace std; struct node{ char name[10]; int year; int month; node* next; }; struct list{ list(); node* begin; node* end; int length; }; list::list(){ begin = new node; end = new node; begin->next = end; end->next = 0; } void make_list(list& l,int n); void output_list(const list& l); void delete_node(list& l,int i); int main(void){ list members; make_list(members,7); output_list(members); delete_node(members,2); output_list(members); getchar();getchar(); return 0; } void make_list(list& l,int n){ node* current = l.begin; for(int i=1;i<=n;i++){ cout<<"input node"<<i<<":"; node* t = new node; cin>>l.end->name>>l.end->year>>l.end->month; current->next = l.end; l.end->next = t; current = l.end; l.end = t; } } void output_list(const list& l){ node* current = l.begin->next; while(current->next!=0){ cout<<current->name<<" "<<current->year<<" "<< current->month<<endl; current = current->next; } cout<<endl; } void delete_node(list& l,int i){ node* current = l.begin->next; if(i==1){ l.begin->next = l.end; return; } for(int t=1;t<i-1;t++) current = current->next; if(!current) exit(0); current->next = current->next->next; }
上一篇:无交换的quicksort
下一篇:一维背包
登录 注册