#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node *next;
};
struct Node
{
struct node *data;
struct Node *next;
};
struct node *head=NULL;
struct Node *head2=NULL;
struct node* creatnode(int n)
{
struct node* newnode=(struct node *)malloc(sizeof(struct node));
newnode->data=n;
newnode->next=NULL;
return newnode;
}
struct Node* Creatnode(struct Node *n)
{
struct Node* newnode=(struct node *)malloc(sizeof(struct node));
newnode->data=&n;
newnode->next=NULL;
return newnode;
}
struct node *insert(struct node *head,int n)
{
struct node* current;
struct node* last;
struct node* newnode=creatnode(n);
if(head==NULL)
{
head=newnode;
return head;
}
current=head;
while((n>=(current->data))&&(current->next!=NULL))
{
last=current;
current=current->next;
}
if(n<=current->data)
{
if(current==head)
{
newnode->next=head;
return newnode;
}else{
newnode->next=last->next;
last->next=newnode;
return head;
}
}else{
current->next=newnode;
return head;
}
}
struct Node* Insert(struct node *head,struct node *data)
{
struct Node *Current;
struct Node *newnode=Creatnode(&data);
if(head==NULL)
{
head=newnode;
return head2;
}
Current=head;
while(Current->next!=NULL)
{
Current=Current->next;
}
Current->next=newnode;
return head2;
}
struct node* find(int n)
{
struct node *current;
current=head;
while(current&¤t->data!=n)
{
current=current->next;
}
return current;
}
struct node* select(int n)
{
struct Node* head2=NULL;
int cnt;
int i;
struct node* current;
struct Node* Current;
current=head;
Current=head2;
while(current)
{
if(current->data==n)
{
Insert(head2,¤t->data);
}
current=current->next;
}
return head2;
}
int update(int n,int m)
{
int cnt=0;
struct Node *Current=head2;
head2=select(n);
struct node *current=head;
while(Current)
{
cnt++;
*Current->data=m;
Current=Current->next;
}
return cnt;
}
int main()
{
int m;
head=insert(head,3);
head=insert(head,5);
head=insert(head,1);
head=insert(head,1);
head=insert(head,2);
head=insert(head,2);
struct node *p;
p=head;
m=update(2,7);
while (p!=NULL)
{
printf("%d ", p->data);
p=p->next;
}
return 0;
}
我想通过select函数把数值为N的地址都存到另一个链表中,再通过这些地址修改值,应该怎么做?