#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int data;
struct node *naxt;
}NODE, *PNODE;
void insert(PNODE head,int data)
{
PNODE p = (PNODE)malloc(sizeof(NODE));
p->data = data;
p->naxt = NULL;
#if 0
p->naxt = head->naxt;
head->naxt = p;
#else
PNODE temp;
temp = head;
while (temp->naxt != NULL)
{
temp = temp->naxt;
}
temp->naxt = p;
#endif
}
void findNODE(PNODE head, int data)
{
PNODE temp = head->naxt;
while(temp!= NULL)
{
if (temp->data==data)
{
}
temp = temp->naxt;
}
}
void changeNODE(PNODE head, int data, int newdata)
{
PNODE temp = head->naxt;
while (temp != NULL)
{
if (temp->data == data)
{
temp->data = newdata;
}
temp = temp->naxt;
}
}
void deleNODE(PNODE head, int data)
{
PNODE p= head;
while (p->naxt != NULL)
{
if (p->naxt->data == data )
{
PNODE temp = p->naxt ;
p->naxt = p->naxt->naxt;
free(temp);
}
p = p->naxt;
}
}
void deleAllNODE(PNODE head)
{
PNODE temp;
while (head != NULL)
{
temp = head;
head = head->naxt;
free(temp);
}
}
void ptint(PNODE head)
{
PNODE temp = head->naxt;
while (temp!=NULL)
{
printf("%d->", temp->data);
temp = temp->naxt;
}
printf("NULL\n");
}
int main()
{
PNODE head;
head = (PNODE)malloc(sizeof(NODE));
head->naxt = NULL;
for (int i = 0; i < 10; i++)
{
insert(head, i);
}
deleNODE(head, 2);
ptint(head);
deleAllNODE(head);
system("pause");
return 0;
}
|