#include "stdafx.h"
#define _CRT_SECURE_NO_WARNINGS
#include<stdlib.h>
#include<stdio.h>
#include<malloc.h>
typedef struct Node {
struct Node* next;
int data;
};
typedef struct Node *PtrToNode;
typedef PtrToNode List;
typedef PtrToNode Position;
typedef int ElementType;
List CreateLink()
{
Node *list = (Node*)malloc(sizeof(Node));
list->next = NULL;
return list;
}
Node* findLinkLast(Node* list) {
while (list->next) {
list = list->next;
}
return list;
}
void insert(Node* list, int a) {
Node *p = (Node*)malloc(sizeof(Node));
p->data = a;
p->next = NULL;
Node* q = findLinkLast(list);
q->next = p;
}
Position Advance(Position P)
{
return P->next;
}
ElementType
Retrieve(Position P)
{
return P->data;
}
void PrintLots(List L, List P)
{
Position l_pos, p_pos;
l_pos = L;
p_pos = P;
int i = 0;
p_pos = Advance(p_pos);
while (p_pos != NULL && l_pos != NULL)
{
int num = Retrieve(p_pos);
for (; i < num; i++)
{
l_pos = Advance(l_pos);
}
if (l_pos == NULL) break;
printf("%d\n", Retrieve(l_pos));
p_pos = Advance(p_pos);
}
}
int main()
{
List L = CreateLink();
List P = CreateLink();
insert(L, 1);
insert(L, 2);
insert(L, 3);
insert(L, 4);
insert(L, 5);
insert(L, 6);
insert(P, 1);
insert(P, 2);
insert(P, 3);
insert(P, 4);
insert(P, 5);
PrintLots(L, P);
system("pause");
return 0;
}