// 1123.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "malloc.h"
#include "string.h"
/*---------------------------|
| list {node1,node2} |
|___________________________*/
struct datatype{
int age;
char * pname;
};
struct node{
struct node * next;
struct datatype data;
};
/*----------------------|
| |
| init list |
|-----------------------*/
int InitList(node * list, int n){
list = (node *)malloc(sizeof(node)*n);
if (list == NULL)
return -1;
(list->data).age= 0 ;
(list->data).pname=NULL;
list->next = NULL;
return 0;
}
int AppendList(node * list , node *a){
while(list->next != NULL)
list = list->next;
list->next = a;
a->next = NULL;
return 0;
}
int DeleteList(node * list , node a ){
while(strcmp(list->data.pname, a.data.pname)!=0 ||
list->data.age != a.data.age)
{
list = list->next;
}
list = list->next->next;
return 0;
}
int DestroyList(node * list){
free(list);
return 0;
}
int main(){
struct node head ;
struct node node1;
memset(&head,0x00,sizeof(struct node));
int ret = InitList(&head, 3);
if (ret == -1) {
printf(" malloc error \n");
}
ret = AppendList(&head, &node1);
if (ret != 0) {
printf("error in append\n");
}
free(head);
return 0;
}
//
#include "stdafx.h"
#include "malloc.h"
#include "string.h"
/*---------------------------|
| list {node1,node2} |
|___________________________*/
struct datatype{
int age;
char * pname;
};
struct node{
struct node * next;
struct datatype data;
};
/*----------------------|
| |
| init list |
|-----------------------*/
int InitList(node * list, int n){
list = (node *)malloc(sizeof(node)*n);
if (list == NULL)
return -1;
(list->data).age= 0 ;
(list->data).pname=NULL;
list->next = NULL;
return 0;
}
int AppendList(node * list , node *a){
while(list->next != NULL)
list = list->next;
list->next = a;
a->next = NULL;
return 0;
}
int DeleteList(node * list , node a ){
while(strcmp(list->data.pname, a.data.pname)!=0 ||
list->data.age != a.data.age)
{
list = list->next;
}
list = list->next->next;
return 0;
}
int DestroyList(node * list){
free(list);
return 0;
}
int main(){
struct node head ;
struct node node1;
memset(&head,0x00,sizeof(struct node));
int ret = InitList(&head, 3);
if (ret == -1) {
printf(" malloc error \n");
}
ret = AppendList(&head, &node1);
if (ret != 0) {
printf("error in append\n");
}
free(head);
return 0;
}
回复Comments
{commenttime}{commentauthor}
{CommentUrl}
{commentcontent}