Chinaunix首页 | 论坛 | 博客
  • 博客访问: 38497
  • 博文数量: 64
  • 博客积分: 2640
  • 博客等级: 少校
  • 技术积分: 670
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-26 13:15
文章分类
文章存档

2010年(64)

我的朋友
最近访客

分类: C/C++

2010-01-26 13:45:06

2008-10-02 11:38


#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;
}


阅读(173) | 评论(0) | 转发(0) |
0

上一篇:无交换的quicksort

下一篇:一维背包

给主人留下些什么吧!~~