重新完善
#include <stdio.h>
#include <stdlib.h>
typedef struct Node
{
int password;
int sequence;
struct Node* next;
}Link;
Link* Creat(Link* head, int* sequence);
Link* Find(Link* head, int password);
Link* Delete(Link* head, Link* target);
int main()
{
int sequence = 0;
int password = 0;
int* pSequence = &sequence;
Link* pHead = NULL;
Link* pTarget = NULL;
pHead = Creat(pHead,pSequence);
printf("Please input a password:");
scanf("%d",&password);
pTarget = Find(pHead,password);
if (pTarget)
{
printf("%d->",pTarget->sequence);
password = pTarget->password;
pHead = Delete(pHead,pTarget);
}
while (pHead != NULL)
{
pTarget = Find(pHead,password);
if (pTarget)
{
printf("%d->",pTarget->sequence);
password = pTarget->password;
pHead = Delete(pHead,pTarget);
}
else
{
free(pHead);
break;
}
}
return 0;
}
Link* Creat(Link* head, int* sequence)
{
Link* pNewNode = NULL;
Link* pIter = NULL;
int password = 0;
while (scanf("%d",&password) != EOF)
{
pNewNode = (Link*)malloc(sizeof(Link));
pNewNode->password = password;
pNewNode->next = NULL;
if (head == NULL)
{
head = pNewNode;
}
else
{
for (pIter=head; pIter->next!=NULL; pIter=pIter->next)
{
continue;
}
*sequence = *sequence + 1;
pIter->next = pNewNode;
pIter->sequence = *sequence;
}
}
pNewNode->next = head;
return head;
}
Link* Find(Link* head, int password)
{
Link* pIter = head;Link* pIter2=head;
for (; pIter!= NULL&&pIter->password!=password; pIter=pIter->next)
if (pIter->next==pIter2)
{
if (pIter->password==password)
{
return pIter;
}
return NULL;
}
return pIter;
}
Link* Delete(Link* head, Link* target)
{
Link* pIter = NULL;
for (pIter=head; pIter->next!=target; pIter=pIter->next)
{
continue;
}
if (target->next == target)
{
printf("%d\n",target->sequence);
head=NULL;
}
else
{
pIter->next = target->next;
head = target->next;
}
free(target);
return head;
}
#include <stdio.h>
#include <stdlib.h>
typedef struct Node
{
int password;
int sequence;
struct Node* next;
}Link;
Link* Creat(Link* head, int* sequence);
Link* Find(Link* head, int password);
Link* Delete(Link* head, Link* target);
int main()
{
int sequence = 0;
int password = 0;
int* pSequence = &sequence;
Link* pHead = NULL;
Link* pTarget = NULL;
pHead = Creat(pHead,pSequence);
printf("Please input a password:");
scanf("%d",&password);
pTarget = Find(pHead,password);
if (pTarget)
{
printf("%d->",pTarget->sequence);
password = pTarget->password;
pHead = Delete(pHead,pTarget);
}
while (pHead != NULL)
{
pTarget = Find(pHead,password);
if (pTarget)
{
printf("%d->",pTarget->sequence);
password = pTarget->password;
pHead = Delete(pHead,pTarget);
}
else
{
free(pHead);
break;
}
}
return 0;
}
Link* Creat(Link* head, int* sequence)
{
Link* pNewNode = NULL;
Link* pIter = NULL;
int password = 0;
while (scanf("%d",&password) != EOF)
{
pNewNode = (Link*)malloc(sizeof(Link));
pNewNode->password = password;
pNewNode->next = NULL;
if (head == NULL)
{
head = pNewNode;
}
else
{
for (pIter=head; pIter->next!=NULL; pIter=pIter->next)
{
continue;
}
*sequence = *sequence + 1;
pIter->next = pNewNode;
pIter->sequence = *sequence;
}
}
pNewNode->next = head;
return head;
}
Link* Find(Link* head, int password)
{
Link* pIter = head;Link* pIter2=head;
for (; pIter!= NULL&&pIter->password!=password; pIter=pIter->next)
if (pIter->next==pIter2)
{
if (pIter->password==password)
{
return pIter;
}
return NULL;
}
return pIter;
}
Link* Delete(Link* head, Link* target)
{
Link* pIter = NULL;
for (pIter=head; pIter->next!=target; pIter=pIter->next)
{
continue;
}
if (target->next == target)
{
printf("%d\n",target->sequence);
head=NULL;
}
else
{
pIter->next = target->next;
head = target->next;
}
free(target);
return head;
}
★★★★★为人民服务★★★★★