- #include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct Information
{
char Name[10];
int KB;//开放表示为0,不开放表示为1;
float Pos;//位置根据平面图拟定;
int Type;//信号机性质,列车信号取1,调车信号取0;
struct date;
struct Information*next,*front;//前一信号机指针,后一信号机指针;
}Signal,*pSignal;
//创建双链表
pSignal createDlist(pSignal head)
{
if(head==NULL)
{
}head=(pSignal)malloc(sizeof(Information)); head->front=NULL;//将*head的后继赋值为空; head->next=NULL;//将*head的前驱赋值为空;
}return head;
Information getSignal()//将所需要的数据传给信息链表
{
Information information;
printf("\t信号机名称:");
scanf("\t%s",&information.Name);
printf("\t信号机开放状态:");
scanf("\t%d",&information.KB);
printf("\t信号机地址:");
scanf("\t%f",&information.Pos);
printf("\t闭锁继电器状态:");
scanf("\t%d",&information.Type);
return information;
}
//插入信息
pSignal insertSignal(pSignal head)
{
if(head==NULL)
{
}head=createDlist(head);
pSignal p=(pSignal)malloc(sizeof(struct Information));
p->date - =getSignal();
if(head->next==NULL)
{
}p->next=head->next; head->next=p; p->front=head; return head;
p->next=head->next;
head->next->front=p;//将p赋值给p->next的后继;
head->next=p;
p->front=head;
return head;
}
//删除信息
void delete_xinhaoji(pSignal head)
{
char Signal_num[20];
printf("\t请输入要删除的信号机的名称:");
scanf("%s",Signal_num);
pSignal temp;
for(temp=head->next;temp!=NULL;temp=temp->next)
{
}if(strcmp(temp->Name,Signal_num)==0) { // 找到需要删除节点的位置 pSignal front=temp->front; pSignal next=temp->next; //进行删除操作; front->next=next; next->front=front; free(temp);//释放temp所占用的内存; printf("\t\t\t删除信号机成功!\n"); return ; }
if(temp==NULL)
{
}printf("\t无此信号机!\n");
}
int main()
{ pSignal head=NULL;//让Signal的头指针为空指针;
head=createDlist(head);
insertSignal(head);
insertSignal(head);
insertSignal(head);
insertSignal(head);//调用四次insert函数,插入四组数据;
delete_xinhaoji(head);//调用delete函数;
printf("\t");
system("Pause");
return 0;
}
4.
5.
-