zoukankan      html  css  js  c++  java
  • c++ 双向链表 的查找和删除

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    #include <stdarg.h> 
    #include <time.h>
    
    struct mytime
    {   
        //char name[256];
        int hour;//
        int min; //
        int sec; //
    };
    
    struct  stu_data
    {
        char name[256];//学生名字
        int sex;//0女生,非0表男生
        struct mytime stuTime;//签到时间
        struct  stu_data* front; //指向前一个结点
        struct  stu_data* back;  //指向后一个结点
    
    }  ;
    
    //搜索 查询
    
     struct  stu_data * FindNode(struct  stu_data* Head,char* Name)
    {
         struct  stu_data * stu;
         stu=Head->back;
         do 
         {
             if (strcmpi(stu->name,Name)==0)//不区分大小写 判断相等
             {
                 printf("%s,到校时间:%d时%d分%d秒
    ",stu->name, stu->stuTime.hour, stu->stuTime.min, stu->stuTime.sec);
                 if (stu->sex)
                 {
                 printf("");
                 }else             printf("");
                 return stu;
             }
             stu=stu->back;
         } while (stu!=Head->back);
     
         return NULL;
     }
     
     
     int main(int argn,char* argv[])// int a[1]//a[0]
     {       
        
    
         struct mytime t2;
         struct stu_data *stu,*p,*Head,*tail;
         
         time_t t;// long int
         struct tm * timfo;
         int i;
     
         //建立Head头结点
         Head=p=tail=malloc(sizeof( struct stu_data)); //256+12=268
         memset(p,0,sizeof( struct stu_data));
         strcpy(Head->name,"头结点");
        
         
         
         do
         {//插入新的结点
             stu= malloc(sizeof( struct stu_data)); //
             memset(stu,0,sizeof( struct stu_data)); //初始化内存区域
    
             //stu->back=NULL; //新结点尾指针置空
             //p->back=stu; //前驱结点back指针指向新结点
             //p=stu; //重要移动标志指针
    
             stu->front=p; //新结点指向前驱  2
             stu->back=NULL; //新结点尾指针置空
             p->back=stu; //前驱结点back指针指向新结点
             p=stu; //重要移动标志指针
             tail=stu;//可有可无的  2
    
             scanf("%s",&stu->name);
             time(&t);
             timfo= localtime(&t); //取当前系统时间 
             stu->stuTime.hour=timfo->tm_hour;//
             stu->stuTime.min=timfo->tm_min;//
             stu->stuTime.sec=timfo->tm_sec;////构建循环链表
             Head->front=stu;
             tail->back=Head;
    
         } while(strcmpi(stu->name,"exit")!=0);
     
         //初始指针p 使他头结点Head
         //stu=Head->back;
         //do 
         //{
            //  printf("%s,到校时间:%d时%d分%d秒
    ",stu->name, stu->stuTime.hour, stu->stuTime.min, stu->stuTime.sec);
    
            // stu=stu->back;
         //} while (strcmpi(stu->name,"exit"));
    
    
       printf("
    
     找到的结点地址:%x", FindNode(Head,"s2"));
    
    
    
         
     
    
     
        getchar();
        getchar();
        
        return 0;
    }

     删除

  • 相关阅读:
    centos7下磁盘空间调整
    centos7下 查看CPU、内存、磁盘的使用情况
    centos7中Spark集群的安装与配置(Hadoop2.6.5+spark2.3.3)
    linux下mysql ---- Host '' is not allowed to connect to this MySQL server
    11-1、多线程
    10-2、对象的序列化和反序列化
    9-1、注解
    8-1、泛型
    7-1、集合
    6-1、异常处理
  • 原文地址:https://www.cnblogs.com/whzym111/p/6140384.html
Copyright © 2011-2022 走看看