码迷,mamicode.com
首页 > 其他好文 > 详细

线性表[ACM] (有bug)有待修改

时间:2014-05-19 22:08:01      阅读:368      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   c   code   java   

bubuko.com,布布扣
 1 #include "iostream"
 2 #include "string"
 3 using namespace std;
 4 
 5 typedef struct node{
 6     string data;
 7     struct node *next;
 8     node(string str){
 9         data=str;
10         next=NULL;
11     }
12 
13 }Node;
14 
15 
16     Node *head=new node("hfirst");
17     Node *back=new node("bfirst");
18     Node *current=NULL;
19     Node *pre=head;
20 
21 
22 void add(string str){
23     Node *temp;
24     if(back->data=="bfirst")
25         temp=new Node(str);
26     else{
27         temp=back->next;
28         back->next=temp->next;
29         temp->data=str;
30         temp->next=NULL;
31     }
32     temp->next=head->next;
33     head->next=temp;
34     current=temp;
35 }
36 
37 void move(int p){
38     int i=0;
39     for(;i<p;i++){
40         pre=current;
41         if(current==NULL){
42             cout<<"worng!!!"<<endl;
43             current=head->next;
44             pre=head;
45             break;
46         }
47         else
48             current=current->next;
49     }
50 
51 }
52 
53 void del(int i){
54     Node *temp=current;
55     Node *tp;
56     while(i!=0&&current!=NULL){
57         tp=current;
58         current=current->next;
59     }
60     if(current==NULL){
61         back->next=pre->next;
62         pre->next=NULL;
63         pre=head;
64         current=head->next;
65     }
66     else{
67         pre->next=current;
68         temp->next=back->next;
69         back->next=temp;
70     }
71     
72 }
73 void _print(){
74     cout<<current->data;
75 }
76 
77 
78 void main(){
79     string choice,str;
80     int i;
81     while(1){
82     cin>>choice;
83         if (choice==("ADD")){cin>>str;add(str);}
84         if (choice==("MOVE")){cin>>i;move(i);}
85         if (choice==("DEL")){cin>>i;del(i);}
86         if (choice==("PRINT"))_print();
87     }
88     getchar();
89 }
bubuko.com,布布扣

 

线性表[ACM] (有bug)有待修改,布布扣,bubuko.com

线性表[ACM] (有bug)有待修改

标签:style   blog   class   c   code   java   

原文地址:http://www.cnblogs.com/593213556wuyubao/p/3731418.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!