zoukankan      html  css  js  c++  java
  • 链表


    #include "stdafx.h"
    #include <stdlib.h>   
    #include <stdio.h>  
    #include <assert.h>
    #include <fstream>


    using namespace std;


    const int MAX_SIZE = 256;
      
    struct node
    {  
        char *str;  
        struct node *next;  
    };  
      


     void InsertWord( char * str, node **head)  
    {  
        int i=0;  
        struct node *p,*element;  
    p = *head;
      
    int len = strlen(str);
    char * strp = (char*)malloc(sizeof(len +1));
    assert( (strp != NULL)&&(str != NULL));
    strcpy(strp,str);
    if(p->next == NULL && p->str == NULL)
    {
    p->str = strp;
    }
    else
    {
          element=(struct node*)malloc(sizeof(struct node));  
     assert(element != NULL);
          memset(element, 0, sizeof(struct node));  
     element->str = strp;


     element->next = p->next;
          p->next=element; 
     p = element;


    }
    }  
     
      
    void GetWords( node **head)
    {
    char str[ MAX_SIZE];
    ifstream InFile("E:\\test.txt");
    while(!InFile.eof())
    {
    InFile.getline(str,MAX_SIZE);
    const char *split = " ,;*.";
    char *p = strtok(str,split);
    while(p != NULL)
    {
    InsertWord(p,head);
    p = strtok(NULL,split);
    }
    }

    }




     node * Init()
     {
    node * p = (node*)malloc(sizeof(node));
    p ->str = NULL;
    p->next = NULL;
    return p;
     }


    void print( node*head){  
        struct node *temp;  
          
        temp=head;          
        while(temp!=NULL)              
        {  
            printf("%s\n",temp->str);        
            temp=temp->next;         
        }  
    }   


    int _tmain(int argc, _TCHAR* argv[])
    {
    node *head;
    head = Init();
         
        GetWords(&head);
    print(head); 
        return 0; 


    }

  • 相关阅读:
    bodyparser中间件
    socket编程server端
    快速搭建ELK日志分析系统
    windows下nginx+php-cgi多端口
    c#中bin,obj,properties文件夹的作用
    宝塔面板Linux命令大全
    c#串口编程(转)
    git push.default设置
    PHP在RS232串口通讯协议的应用演示[测试环境WinXP/PHP5.1.4]
    Windows下的串口编程
  • 原文地址:https://www.cnblogs.com/dyufei/p/2573899.html
Copyright © 2011-2022 走看看