• 简单链表


    #include <iostream>
    #include <stdlib.h>
    using namespace std;
    struct node{
      int data;
      struct node *link;
    };
    typedef struct node *plist;
    plist creat_list(int m){
      plist head=(plist)malloc(sizeof(plist));
      plist next=(plist)malloc(sizeof(plist));
      head->link=next;
      while(m--){
        plist p=(plist)malloc(sizeof(plist));
        next->link=p;
        next=next->link;
        next->link=NULL;
      }
      cout<<"creat successful"<<endl;
      return head;
    }
    void show_data(plist p){
      int i=1;
      while(p->link!=NULL){
        cout<<"output:"<<i<<' '<<p->data<<endl;
        p=p->link;i++;
      }
    }
    void cin_data(plist p){
      while(p->link!=NULL){
        cin>>p->data;
        p=p->link;
        cout<<"succeful"<<endl;
      }
    }
    void del_data(plist p,int m){
        while(p->link->data!=m&&p->link!=NULL)p=p->link;
        p->link=p->link->link;
        cout<<"successful!"<<endl;
    }

    int main()
      {

        plist head;
        bool flag=true;
       while(flag){
         printf("choose you want to do :          ");
         printf("   1,creat_list                  ");
         printf("   2,input data for list         ");
         printf("   3,show all data you hava input ");
         printf("   4,delte                       ");
         printf("   5,exit                        ");
         int n;
         cin>>n;
         switch(n){
           case 1:
              cout<<"how mach ?"<<endl;
              int m;cin>>m;
              head=creat_list(m);
              break;
           case 2:
              cin_data(head);
              cout<<"ddd";
              break;
          case 3:
             show_data(head);
             break;
          case 4:
             int l;
             cout<<"Enter what you want to delete"<<endl;
             cin>>l;
             del_data(head,l);
             break;
          case 5:
             flag=false;

        }
       }

        return 0;
      }

  • 相关阅读:
    getBoundingClientRect()方法
    Sublime Text3 安装less
    less知识点总结(一)
    跨域知识(二)——JSONP
    面向过程和面向对象的区别(转)
    暴力+DP:买卖股票的最佳时机
    车的可用捕获量(3.26leetcode每日打卡)
    三维形体的表面积(3.25leetcode每日打卡)
    基础练习:FJ的字符串
    DP:打家劫舍
  • 原文地址:https://www.cnblogs.com/yusuph/p/13696871.html
Copyright © 2020-2023  润新知