mamn

#include<bits/stdc++.h>
using namespace std;
struct node{
    node *next;
    char name[20];
    char id[20];
    int len;
};
node *head;
void init(node* &head)
{
     
    head=(node*)malloc( sizeof (node ));
    head->next=NULL;
    head->len=0;
//  head->name=NULL;
//  head->id=NULL;
}
void insert(node* &head,char* name,char* id)
{
    node * L=head;
    while(L)    {
    //  cout<<"--"<<endl;
        L=L->next;
        }
    L=(node*)malloc(sizeof (node));
    strcpy(L->name,name);
    strcpy(L->id,id);
    //cout<<L->name<<" "<<L->id<<endl;
    head->len++;
    L->next=head->next;
    head->next=L;
}
void modify(node* &List,int k,char name[],char id[])
{
    if(k>List->len)   {
        cout<<"len to short!"<<endl;
        return ;
    }
    k=List->len-k+1;
    node* L=List;
    while(k--)
    {
        L=L->next;
    }
    strcpy(L->name,name);
    strcpy(L->id,id);
}
void del(node* &List,int k)
{
    if(k>List->len)   {
        cout<<"len to short!"<<endl;
        return ;
    }
    k=List->len-k+1;
    node*L=List;
    while(--k)
    L=L->next;
    L->next=(L->next->next);
}
void print(node *L)
{
    node *head=L;
    head=head->next;
    int cnt=0;
    cout<<"print the list"<<endl;
    while(head)
    {
        cnt++;
        cout<<cnt<<" "<<head->id<<" "<<head->name<<endl;
        head=head->next;
    }
}
void query(node *L,int k)
{
    node*x=L;
    k=L->len-k+1;
    if(k>L->len)
    {
        cout<<"len too short"<<endl;
        return ;
    }
    for(int i=0;i<k;i++)
    {
        x=x->next;
    }
    cout<<k<<" "<<x->id<<" "<<x->name<<endl;
}
int main()
{
    cout<<"welcome to here!"<<endl;
    int opt;
    while(cin>>opt)
    {
         
    if(opt==1)
    {
        init(head);
    }
    else if(opt==2)
    {
        char name[20];
        char id[20];
        cin >> name >> id;
        insert(head,name,id);
    //  cout<<head->len<<endl;
        //cout<<(head->next)->name<<endl;
    }
    else if(opt==3)
    {
        int k;
        cin>>k;
        query(head,k);
    }
    else if(opt==4)
    {
        int k;
        cin>>k;
        char name[20];
        char id[20];
        cin >> name >> id;
        modify(head,k,name,id);
    }
    else if(opt==5)
    {
        int k;
        cin>>k;
        del(head,k);
    }
    else if(opt==6)
    {
            print(head);
    }
    else if(opt==7)
    {
        cout<<"Quit..."<<endl;
        return 0;
    }
 
    }
    return 0;
}
/*
1
2
myq
120
 
*/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值