0

I'm trying to implement a hashtable with linked list and there is one thing not working properly. First i made the linked list code and made sure it worked just as it is supposed to, so I figured out it got to be something with the hashtable implementation or the interaction between them both.

What happens is i can add several objects and find them again with no problem. But if two or more objects are hashed with the same key they are supposed to create a linked list but for some reason i can only find the latest added object in the linked list.

The previously added object is there though because i can successfully delete the object that i cannot find with my "lookup_string" function, so therefor i know the object is stored at that spot.

So the function "lookup_string" is supposed to deliver the object i search for in the hash table and the "Search" function is the one i used when I only implemented the linked list. Worth mentioning is that the "Search" function is used in the delete-process but not in the process where i just want to find an object, I'm not sure if this matters because i believe the "lookup_string" should be able to find an object without the "Search" function.

So to make this simple, I store two objects:

Object 1:

name(key) = bcd
telephone number = 123

Object 2:

name(key) = ace
telephone number = 910

Now both object 1 and 2 will get the same hash-key value and therefor they will be stored in the same slot in the hash-table. They are supposed to create a linked list but when i search for the objects (choice number 3 in the menu) i can only find the latest added object, which is Object 2. But i can still delete Object 1 and it will tell me that Object 1 was deleted successfully.

Code:

struct post
{   
    char name[30];          
    int tel;                
    struct post *next;      
};

typedef struct post Post;

Post *head = NULL;  
Post *current;  

struct hash_table
{
    Post **table;
    int size;
};

typedef struct hash_table Post_table;

unsigned int Hash(Post_table *hash_table, char tempname[30])
{
    int i;
    int sum;
    int key;
    for(i = 0; i < strlen(tempname); i++)
    {
        sum += (int)tempname[i];
    }

    key = sum % hash_table->size;
    return key;
}

Post_table *create_hash_table(int size)
{
    int i;
    Post_table *new_table;

    if (size < 1)
    {
        return NULL;
    }

    //attempt to allocate memory for the table structure
    if ((new_table = malloc(sizeof(Post_table))) == NULL)
    {
        return NULL;
    }

    //attempt to allocate memory for the table itself
    if ((new_table->table = malloc(sizeof(Post *) * size)) == NULL)
    {
        return NULL;
    }

    //Initialize the elements of the table
    for(i = 0; i < size; i++)
    {
        new_table->table[i] = NULL;
        new_table->size = size;
    }
    return new_table;
}

Post *lookup_string(Post_table *hash_table, char tempname[30])
{
    Post *list;
    unsigned int hashkey = Hash(hash_table, tempname);

    for(list = hash_table->table[hashkey]; list != NULL; list = list->next)
    {
        if (strcmp(tempname, list->name) == 0)
        {
            return list;
        }
    }
    return NULL;
}

int add_string(Post_table *hash_table, char tempname[30], int temptel)
{
    Post *new_list;
    Post *current_list;
    unsigned int hashkey = Hash(hash_table, tempname);

    /* Attempt to allocate memory for list */
    if ((new_list = malloc(sizeof(Post))) == NULL)
    {
        return 1;
    }

    /* Does item already exist? */
    current_list = lookup_string(hash_table, tempname);
    /* item already exists, don't insert it again. */
    if (current_list != NULL)
    {
        return 2;
    }
    /* Insert into list */

    printf("\nHash-key: %d\n", hashkey); 
    hash_table->table[hashkey] = AddList(tempname, temptel);

    return 0;
}

Post* CreateList(char tempname[30], int temptel)
{   
    Post *ptr = (Post*)malloc(sizeof(Post));

    strcpy(ptr->name, tempname);    
    ptr->tel = temptel;
    ptr->next = NULL;

    printf("\n creating list with headnode as [%s]\n",tempname);

    head = current = ptr;
    return ptr;
}

Post* AddList(char tempname[30], int temptel)
{
    if (NULL == head)
    {
        return (CreateList(tempname, temptel));
    }

    printf("\n Adding node to end of list with value [%s]\n",tempname);
    Post *ptr = (Post*)malloc(sizeof(Post));

    strcpy(ptr->name, tempname);
    ptr->tel = temptel;
    ptr->next = NULL;

    current->next = ptr;
    current = ptr;
    return ptr;
}

void skrivMeny(void)
{
    printf("\n1: Register name and telephone number\n");
    printf("2: Remove name and telephone number\n");
    printf("3: Search for name\n");
    printf("5: Exit\n");
}

Post* Search(char tempname[30], Post **prev)
{
    Post *ptr = head;
    Post *tmp = NULL;
    int found = 0;
    char structname[sizeof(tempname)];

    printf("\n Searching the list for value [%s] \n",tempname);

    while(ptr != NULL)
    {   
        if (strcmp(ptr->name, tempname) == 0)
        {
            found = 1;
            break;
        }
        else
        {
            tmp = ptr;
            ptr = ptr->next;
        }
    }

    if(found == 1)
    {
        if(prev)
        {
            *prev = tmp;
        }
        return ptr;
    }
    else
    {
        return NULL;
    }
}

void free_entry(Post_table *hash_table, char tempname[30])
{
    Post *del_list;
    Post *temp;
    int ret = 0;

    unsigned int hashkey = Hash(hash_table, tempname);
    del_list = lookup_string(hash_table, tempname);

    ret = Delete(tempname);

    if(ret != 0)
    {
        printf("\n delete [name = %s] failed, no such element found\n",tempname);
    }
    else
    {
        printf("\n delete [name = %s]  passed \n",tempname);
    }
}

int Delete(char tempname[30])
{
    Post *prev = NULL;
    Post *del = NULL;

    printf("\n Deleting value [%s] from list\n",tempname);
    del = Search(tempname,&prev);

    if(del == NULL)
    {
        return -1;
    }
    else
    {
        if(prev != NULL)
        {
            prev->next = del->next;
        }
        if(del == current && del != head)
        {
            current = prev;
        }
        else if(del == head)
        {
            head = del->next;
        }
    }

    free(del);
    del = NULL;
    return 0;
}


int main()
{
    printf("\nHej och välkommen till hashlistan\n\n");
    int menyval = 1;
    char tempname[30];
    int temptel;
    int key;

    Post * ptr;

    Post_table *hash_table;
    int table_size = 10;
    hash_table = create_hash_table(table_size);

while (menyval > 0 && menyval <= 5)
{
    skrivMeny();
    scanf("%d", &menyval);

        if (menyval == 1)
        {
            printf("[Name] [Number] = ");
            scanf("%s %d", &tempname[0], &temptel);//inmatning
            add_string(hash_table, tempname, temptel);
        }

        if (menyval == 2)
        {
            printf("[Name] = ");
            scanf("%s", &tempname[0]);
            free_entry(hash_table, tempname);
        }

        if (menyval == 3)
        {
            printf("[Name] = ");
            scanf("%s", &tempname[0]);
            ptr = lookup_string(hash_table, tempname);

            if(ptr == NULL)
            {
                printf("\n Search [name = %s] failed, no such element found\n",tempname);
            }
            else
            {
                printf("\n Search passed [name = %s tel = %d]\n",ptr->name, ptr->tel);
            }
        }
        if (menyval == 5)
        {
            break;
        }

    }
    return 0;
}

I appreciate all help or tips toward solving my problem!

EDIT: This is how my code looks like right now, I divided my file into two files; hash.c and lista.h where i included the header file in the c-file.

lista.h:

struct post
{   
    char name[30];          
    int tel;                
    struct post *next;      
};
typedef struct post Post;

struct list
{
    Post *head = NULL;  
    Post *current;
};
typedef struct list List;

Post* CreateList(char tempname[30], int temptel)
{   
    Post *ptr = (Post*)malloc(sizeof(Post));

    strcpy(ptr->name, tempname);    
    ptr->tel = temptel;
    ptr->next = NULL;

    printf("\n creating list with headnode as [%s]\n",tempname);

    return ptr;
}

Post* AddList(char tempname[30], int temptel, int emptyElement)
{
    if (emptyElement == 1)
    {
        return (CreateList(tempname, temptel));
    }

    printf("\n Adding node to end of list with value [%s]\n",tempname);
    Post *ptr = (Post*)malloc(sizeof(Post));

    strcpy(ptr->name, tempname);
    ptr->tel = temptel;
    ptr->next = NULL;

    return ptr;
}

int Delete(Post_table *hash_table, char tempname[30])
{
    Post *prev = NULL;
    Post *del = NULL;

    printf("\n Deleting value [%s] from list\n",tempname);
    del = Search(tempname,&prev);

    if(del == NULL)
    {
        return -1;
    }
    else
    {
        if(prev != NULL)
        {
            prev->next = del->next;
        }
        if(del == hash_table->table[hashkey].current && del != hash_table->table[hashkey].head)
        {
            hash_table->table[hashkey].current = prev;
        }
        else if(del == hash_table->table[hashkey].head)
        {
            hash_table->table[hashkey].head = del->next;
        }
    }

    free(del);
    del = NULL;
    return 0;
}

hash.c:

struct hash_table
{
    List *table;
    int size;
};

typedef struct hash_table Post_table;

unsigned int Hash(Post_table *hash_table, char tempname[30])
{
    int i;
    int sum;
    int key;
    for(i = 0; i < strlen(tempname); i++)
    {
        sum += (int)tempname[i];
    }

    key = sum % hash_table->size;
    return key;
}

Post_table *create_hash_table(int size)
{
    int i;
    Post_table *new_table;

    if (size < 1)
    {
        return NULL;
    }

    //attempt to allocate memory for the table structure
    if ((new_table = malloc(sizeof(Post_table))) == NULL)
    {
        return NULL;
    }

    //attempt to allocate memory for the table itself
    if ((new_table->table = malloc(sizeof(Post *) * size)) == NULL)
    {
        return NULL;
    }

    //Initialize the elements of the table
    for(i = 0; i < size; i++)
    {
        new_table->table[i] = NULL;
        new_table->size = size;
    }
    return new_table;
}

Post *lookup_string(Post_table *hash_table, char tempname[30])
{
    Post *list;
    unsigned int hashkey = Hash(hash_table, tempname);

    for(list = hash_table->table[hashkey]; list != NULL; list = list->next)
    {
        if (strcmp(tempname, list->name) == 0)
        {
            return list;
        }
    }
    return NULL;
}

int add_string(Post_table *hash_table, char tempname[30], int temptel)
{
    int emptyElement = 0;        
    Post *new_list;
    Post *current_list;
    unsigned int hashkey = Hash(hash_table, tempname);

    /* Attempt to allocate memory for list */
    if ((new_list = malloc(sizeof(Post))) == NULL)
    {
        return 1;
    }

    /* Does item already exist? */
    current_list = lookup_string(hash_table, tempname);
    /* item already exists, don't insert it again. */
    if (current_list != NULL)
    {
        return 2;
    }
    /* Insert into list */
    if (hash_table->table[hashkey] == NULL)
    {
        emptyElement = 1;
    }

    printf("\nHash-key: %d\n", hashkey); 
    hash_table->table[hashkey] = AddList(tempname, temptel);

    if (emptyElement == 1)
    {
            hash_table->table[hashkey].head = hash_table->table[hashkey];
            hash_table->table[hashkey].current = hash_table->table[hashkey];
    }

    if (emptyElement == 0)
    {
            hash_table->table[hashkey].current = hash_table->table[hashkey];
    }

    return 0;
}

void free_entry(Post_table *hash_table, char tempname[30])
{
    Post *del_list;
    Post *temp;
    int ret = 0;

    unsigned int hashkey = Hash(hash_table, tempname);
    del_list = lookup_string(hash_table, tempname);

    ret = Delete(tempname);

    if(ret != 0)
    {
        printf("\n delete [name = %s] failed, no such element found\n",tempname);
    }
    else
    {
        printf("\n delete [name = %s]  passed \n",tempname);
    }
}

void skrivMeny(void)
{
    printf("\n1: Register name and telephone number\n");
    printf("2: Remove name and telephone number\n");
    printf("3: Search for name\n");
    printf("5: Exit\n");
}

Post* Search(char tempname[30], Post **prev)
{
    Post *ptr = head;
    Post *tmp = NULL;
    int found = 0;
    char structname[sizeof(tempname)];

    printf("\n Searching the list for value [%s] \n",tempname);

    while(ptr != NULL)
    {   
        if (strcmp(ptr->name, tempname) == 0)
        {
            found = 1;
            break;
        }
        else
        {
            tmp = ptr;
            ptr = ptr->next;
        }
    }

    if(found == 1)
    {
        if(prev)
        {
            *prev = tmp;
        }
        return ptr;
    }
    else
    {
        return NULL;
    }
}

int main()
{
    printf("\nHej och välkommen till hashlistan\n\n");
    int menyval = 1;
    char tempname[30];
    int temptel;
    int key;

    Post * ptr;

    Post_table *hash_table;
    int table_size = 10;
    hash_table = create_hash_table(table_size);

while (menyval > 0 && menyval <= 5)
{
    skrivMeny();
    scanf("%d", &menyval);

        if (menyval == 1)
        {
            printf("[Name] [Number] = ");
            scanf("%s %d", &tempname[0], &temptel);//inmatning
            add_string(hash_table, tempname, temptel);
        }

        if (menyval == 2)
        {
            printf("[Name] = ");
            scanf("%s", &tempname[0]);
            free_entry(hash_table, tempname);
        }

        if (menyval == 3)
        {
            printf("[Name] = ");
            scanf("%s", &tempname[0]);
            ptr = lookup_string(hash_table, tempname);

            if(ptr == NULL)
            {
                printf("\n Search [name = %s] failed, no such element found\n",tempname);
            }
            else
            {
                printf("\n Search passed [name = %s tel = %d]\n",ptr->name, ptr->tel);
            }
        }
        if (menyval == 5)
        {
            break;
        }

    }
    return 0;
}

But as I said there seems to be something wrong with this part:

struct list
{
    Post *head = NULL;  
    Post *current;
};

And since this is not correct it causes several other errors so I'm trying to see what is wrong with this part first.

4

4 回答 4

0

我决定发布一个关于当前代码的新答案,因为我发现否则它对另一个人来说会比现在更难读

当前代码中的语法错误在这里:

struct list 
{
    Post *head = NULL;  
    Post *current;
};

这不是变量定义,而只是结构的声明。因此,您不能= NULL在此处进行任何赋值 ( ),因为根本没有变量可以赋值。相反,您可以hash_table->table[i].head在分配数组后在循环中初始化,也可以只调用calloc()而不是malloc()使用'\0'.

我猜你的代码中有更多错误,至少我发现

if ((new_table->table = malloc(sizeof(Post *) * size)) == NULL)

那应该是

if ((new_table->table = malloc(sizeof(list stuct) * size)) == NULL) // or calloc() 

但我现在无法查看所有内容。希望能给你足够的继续,

于 2013-07-24T16:50:40.023 回答
0

嘿抱歉,如果我弄错了,但据我所知,您的 lookup_string() 函数会遍历哈希表的最后一个元素(最近添加的那个)。尝试以相反的方式遍历它或使用双向链表。

PS:您不使用您的搜索功能进行一些定制吗?Y 这种查找和搜索的冗余?

快乐编码!

于 2013-07-23T09:15:43.447 回答
0

好的,这里对您的代码进行了一些改进:我用我的标签“Leo”标记了它们

在 list.c 中:

struct post                 // structure of node
{   
    char name[30];          // stored data
    int tel;                // stored data
    struct post *next;      // reference to next node
};

typedef struct post Post;   // Post = struct post

struct list
{
    Post *head;         
    Post *current;              
};

typedef struct list List;

struct hash_table
{
    List *table;
    int size;
};

typedef struct hash_table Post_table;

Post* CreateList(char tempname[30], int temptel);
Post* AddList(char tempname[30], int temptel, int emptyElement, Post *current);
void skrivMeny(void);
void PrintList(void);
int Delete(Post_table *hash_table, char tempname[30], unsigned int hashkey);
Post* Search(Post_table *hash_table, unsigned int hashkey, char tempname[30], Post **prev);

Post* CreateList(char tempname[30], int temptel)
{   
    Post *ptr = (Post*)malloc(sizeof(Post));

    strcpy(ptr->name, tempname);    
    ptr->tel = temptel;
    ptr->next = NULL;

    printf("\n creating list with headnode as [%s]\n",tempname);

    return ptr;
}

// Leo: emptyElement isn't neccessary, we use current==null 
Post* AddList(char tempname[30], int temptel, Post *current)
{
    if( current == null )
    {
        return (CreateList(tempname, temptel));
    }

    printf("\n Adding node to end of list with value [%s]\n",tempname);
    Post *ptr = (Post*)malloc(sizeof(Post));

    strcpy(ptr->name, tempname);
    ptr->tel = temptel;
    ptr->next = NULL;

    // Leo: we must append the new element to current
    current->next = ptr;

    return ptr;
}

在 hash.c 中

unsigned int Hash(Post_table *hash_table, char tempname[30])
{
    int i;
    int sum;
    int key;
    for(i = 0; i < strlen(tempname); i++)
    {
        sum += (int)tempname[i];
    }

    key = sum % hash_table->size;
    return key;
}

Post_table *create_hash_table(int size)
{
    int i;
    Post_table *new_table;

    if (size < 1)
    {
        return NULL;
    }

    //attempt to allocate memory for the table structure
    if ((new_table = malloc(sizeof(Post_table))) == NULL)
    {
        return NULL;
    }

    //attempt to allocate memory for the table itself
    // Leo: replaced malloc() by calloc() so all head and current are initialized with NULL
    if ((new_table->table = calloc(size, sizeof(List *) )) == NULL)
    {
        return NULL;
    }

    //Initialize the elements of the table
    /* Leo: What's that loop for ?
    for(i = 0; i < size; i++)
    {
        new_table->table[i];        // Leo: that line doen't do anything
        new_table->size = size;     // Leo: once is enough, let's have it otside the loop
    }
    */
    new_table->size = size;       // Leo: once is enough, let's have it otside the loop
    return new_table;
}

Post *lookup_string(Post_table *hash_table, char tempname[30])
{
    Post *list;
    unsigned int hashkey = Hash(hash_table, tempname);

    /* Go to the correct list based on the hash value and see if str is
    * in the list.  If it is, return return a pointer to the list element.
    * If it isn't, the item isn't in the table, so return NULL.
    */
    // Leo: we must start with head instead of current
    for(list = hash_table->table[hashkey].head; list != NULL; list = list->next)
    {
        if (strcmp(tempname, list->name) == 0)
        {
            return list;
        }
    }
    return NULL;
}

int add_string(Post_table *hash_table, char tempname[30], int temptel)
{
    //Leo: emptyElement is not used any more (see AddList()
    //int emptyElement = 0;
    //Leo: new_list is never used
    //Post *new_list;
    Post *current_list;
    unsigned int hashkey = Hash(hash_table, tempname);

    /* Attempt to allocate memory for list */
    /* Leo: new_list is never used
    if ((new_list = malloc(sizeof(Post))) == NULL)
    {
        return 1;
    }
    */

    /* Does item already exist? */
    current_list = lookup_string(hash_table, tempname);
    /* item already exists, don't insert it again. */
    if (current_list != NULL)
    {
        return 2;
    }
    /* Insert into list */
    /* Leo: emptyElement isn't used any more 
    if (hash_table->table[hashkey].head == NULL)
    {
        emptyElement = 1;
    }
    */

    printf("\nHash-key: %d\n", hashkey);
    //This line of code under used to store my element in the hash-table but gives now an error 
    //  hash_table->table[hashkey] = AddList(tempname, temptel, emptyElement, hash_table->table[hashkey].current);

    /* Leo: in case of emptyElement == 1 you have called AddList() twice and so created two new list elemens, we replace all of this by the code below
    if (emptyElement == 1)
    {
        hash_table->table[hashkey].head = AddList(tempname, temptel, emptyElement, hash_table->table[hashkey].current);
        hash_table->table[hashkey].current = AddList(tempname, temptel, emptyElement, hash_table->table[hashkey].current);
    }

    if (emptyElement == 0)
    {
        hash_table->table[hashkey].current = AddList(tempname, temptel, emptyElement, hash_table->table[hashkey].current);
    }
    */

    // Leo: Note: if the list for hashKey has not been created yet then both head and current are NULL, otherwise both are != NULL
    hash_table->table[hashkey].current = AddList(tempname, temptel, hash_table->table[hashkey].current);
    // Leo: if the list has been created just now, then both head and current must point to the only list element
    if( hash_table->table[hashkey].head == NULL )
         hash_table->table[hashkey].head = hash_table->table[hashkey].current;

    return 0;
}

void free_entry(Post_table *hash_table, char tempname[30])
{
    Post *del_list;
    Post *temp;
    int ret = 0;

    unsigned int hashkey = Hash(hash_table, tempname);
    del_list = lookup_string(hash_table, tempname);

    ret = Delete(hash_table, tempname, hashkey);

    if(ret != 0)
    {
        printf("\n delete [name = %s] failed, no such element found\n",tempname);
    }
    else
    {
        printf("\n delete [name = %s]  passed \n",tempname);
    }
}

void skrivMeny(void)
{
    printf("\n1: Register name and telephone number\n");
    printf("2: Remove name and telephone number\n");
    printf("3: Search for name\n");
    printf("5: Exit\n");
}

Post* Search(Post_table *hash_table, unsigned int hashkey, char tempname[30], Post **prev)
{
    Post *ptr = hash_table->table[hashkey].head;
    Post *tmp = NULL;
    int found = 0;
    char structname[sizeof(tempname)];

    printf("\n Searching the list for value [%s] \n",tempname);

    while(ptr != NULL)
    {   
        if (strcmp(ptr->name, tempname) == 0)
        {
            found = 1;
            break;
        }
        else
        {
            tmp = ptr;
            ptr = ptr->next;
        }
    }

    if(found == 1)
    {
        if(prev)
        {
            *prev = tmp;
        }
    return ptr;
    }
    else
    {
        return NULL;
    }
}


int main()
{
    printf("\nHej och välkommen till hashlistan\n\n");
    int menyval = 1;
    char tempname[30];
    int temptel;
    int key;

    Post * ptr;

    Post_table *hash_table;
    int table_size = 10;
    hash_table = create_hash_table(table_size);

    while (menyval > 0 && menyval <= 5)
    {
        skrivMeny();
        scanf("%d", &menyval);

        if (menyval == 1)
        {
            printf("[Name] [Number] = ");
            scanf("%s %d", &tempname[0], &temptel);//inmatning
            add_string(hash_table, tempname, temptel);
        }

        if (menyval == 2)
        {
            printf("[Name] = ");
            scanf("%s", &tempname[0]);
            free_entry(hash_table, tempname);
        }

        if (menyval == 3)
        {
            printf("[Name] = ");
            scanf("%s", &tempname[0]);
            ptr = lookup_string(hash_table, tempname);

            if(ptr == NULL)
            {
                printf("\n Search [name = %s] failed, no such element found\n",tempname);
            }
            else
            {
                printf("\n Search passed [name = %s tel = %d]\n",ptr->name, ptr->tel);
            }
        }

        if (menyval == 5)
        {
            break;
        }

    }
    return 0;
}


int Delete(Post_table *hash_table, char tempname[30], unsigned int hashkey)
{
    Post *prev = NULL;
    Post *del = NULL;

    printf("\n Deleting value [%s] from list\n",tempname);
    del = Search(hash_table, hashkey, tempname, &prev);

    if(del == NULL)
    {
        return -1;
    }

    else
    {
        if(prev != NULL)
        {
            prev->next = del->next;
        }

        if(del == hash_table->table[hashkey].current && del != hash_table->table[hashkey].head)
        {
            hash_table->table[hashkey].current = prev;
        }

        else if(del == hash_table->table[hashkey].head)
        {
            hash_table->table[hashkey].head = del->next;
        }
    }

    free(del);
    del = NULL;
    return 0;
}

我还没有编译它,所以现在可能会有一些语法错误,但我希望它清楚整个事情应该如何工作。如果您还有其他问题,请随时提问。

于 2013-08-01T09:24:39.087 回答
0

我认为问题导致混合一个链表和哈希表。该列表未排序,因此哈希表无法指向可以找到具有给定键的所有元素的列表位置。并且还AddList()返回新的列表元素,该元素附加到末尾并存储在hash_table->table[hashkey]. 这就是为什么你只能找到最后一个元素(正如 Mudassir Razvi 已经指出的那样)。因此,您应该为每个散列键创建一个列表(我想是最简单的解决方案),或者按散列键对列表进行排序,并hash_table->table[hashkey]仅在使用该键添加第一个元素时分配(==> if( hash_table->table[hashkey] == NULL )

编辑:如果你想为每个键创建单独的列表,当然你不能有全局变量headcurrent而且每个键只有一对。所以你可以定义:

struct list {
    Post *head;
    Post *current;
}

并让hash_table->table成为 的替代品struct list而不是PostCreateList()已经返回head,因此您可以直接将其分配给table[key].headand table[key].current。现在你要做的其他事情就是传递实际current的 toAddList()然后设置table[key].currentAddList()' 的返回值。那是一种路线图,我想你会来的。

于 2013-07-23T10:14:41.683 回答