#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;
typedef struct node
{
int address;
int data;
int nextAddr;
struct node *next;
}type;
int n = 4 ;
bool f2(struct node * a, int b)
{
if(a->address == b)
return true;
else
return false;
}
int main()
{
int m;
vector<struct node *> vet;
vector<int> value;
struct node *head;
head = (struct node*)malloc(sizeof(struct node));
head->next = nullptr;
head->address = -1;
scanf("%d %d %d", &head->nextAddr, &head->data, &m);
vet.push_back(head);
struct node *temp;
for(int i = 1; i <= head->data; i++)
{
temp = (struct node*)malloc(sizeof(struct node));
scanf("%d %d %d", &temp->address, &temp->data, &temp->nextAddr);
temp->next = nullptr;
vet.push_back(temp);
}
vector<struct node*>::iterator it, its;
for(it = vet.begin(); it!=vet.end(); it++)
{
if((*it)->nextAddr == -1)
{
(*it)->next = nullptr;
}
else
{
its = find_if(vet.begin(), vet.end(), bind2nd(ptr_fun(f2), (*it)->nextAddr ));
if(its == vet.end())
(*it)->next = nullptr;
else
(*it)->next = *(its);
}
}
temp = head;
while(temp!=nullptr)
{
printf("%d\n", temp->data);
temp = temp->next;
}
return 0;
}
接触STL之后。。。
最新推荐文章于 2022-11-24 09:50:06 发布