temp

类别:编程语言 点击:0 评论:0 推荐:

#include "Node.h"
#include <stdlib.h>
#include <iostream>

using namespace std;

int initialize(LinkList& list) {
   int retval = 1;
   int headNumber = 0;
   Node* head = new Node;
   if (NULL != head) {
      head->data = &headNumber;
      head->next = NULL;
      list = head;
      retval = 1;
   } else {
      retval = 0;
   }
   return retval;
}

int cleanup(LinkList& list){
    Node* p = list;
    Node* temp = NULL;
    int retval = 1;
  
    if (NULL == p) {
        retval = 1;  
    } else {
        temp = p->next;
        while (NULL != temp) {
             p = temp->next;
             delete temp;
             temp = p;
        }
        delete list;
        retval = 1;
    }
    return retval; 
}

int insertData(LinkList& list, void* pdata) {
    static int nodeNumber = 0;
    Node* p = list;
    Node* temp = NULL;
    Node* insertOne = new Node;
    int retval = 1;
      
    if (NULL != insertOne) {       
        if (NULL == p) {               
            retval = 0;
        } else {   
            while (NULL != p) {
                temp = p;
                p = p -> next;
            }
            temp->next = insertOne;
            insertOne->data = pdata;
            insertOne->next = NULL;
            nodeNumber++;
            list->data = &nodeNumber;           
            retval = 1;                    
        }
    } else {
        retval = 0;
    }
    return retval;
}

//int searchData(LinkList& list, void* pdata) {
   


/*int deleteData(LinkList& list, void* pdata) {
    Node* p = list;
    int retval;
   
    if (NULL == p) {
        retval = 0;
    } else {
        temp = p->next;
        while () {
       
        }
    }
}*/


#include <iostream>
#include <stdlib.h>
#include "Node.h"
#include <string>
using namespace std;

int main(int argc, char *argv[])
{
  LinkList a;
  char d='h';
  initialize(a);
  cout << *(int*)(a->data);
  insertData(a,&d);
  insertData(a,&d);
  cout << *(int*)(a->data);
  cleanup(a);
 //  cout << *(char*)(a->data);
 
 
 
  system("PAUSE"); 
  return 0;
}


#ifndef NODE_H
#define NODE_H

typedef struct Node {
    void* data;
    Node* next;
}Node,*LinkList;

int initialize(LinkList& list);
int cleanup(LinkList& list);

int insertData(LinkList& list, void* pdata);
int deleteData(LinkList& list, void* pdata); 
int searchData(LinkList& list, void* pdata); // return the index that first find 

#endif

本文地址:http://com.8s8s.com/it/it26356.htm