当前位置:文档之家› 单链表 队列 数据结构实验报告 及结果

单链表 队列 数据结构实验报告 及结果

i=i+1;
}
if(p1!=NULL)
printf("\n the position is:%d",i+1);
else printf("\n x is not been found");
}
linklist *insert (linklist *head,linklist *stud)
{
linklist *p1,*p2,*p0;
return head;}
p1=head;
while (num!=p1->data&&p1->next!=NULL)
{p2=p1;p1=p1->next;}
if(num==p1->data)
{if (p1==head) head=p1->next;
else p2->next=p1->next;
printf("\n deletse:%d\n",num);
}
void main()
{ int i,t;
queuetype array[7];
queue queue1;
xinjian(&queue1);
printf("\n \n input 6 characters: ");
for(i=0;i<6;i++)
scanf("%c",&array[i]);
printf("\n ");
}
#include<stdio.h>
#include<string.h>
#define maxsize 16
typedef char queuetype ;
typedef struct
{ queuetype *base;
int front;
int rear;
}queue;
queue* xinjian(queue *q)
prinf(head);
printf("\n Input a data to query: ");
scanf("%d",&y);
chaxun(head,y);
printf("\n \n Input a data to delete: ");
scanf("%d",&t);
del(head,t);
prinf(head);
}
}
void print(queue *q)
{ int i,j,fr;
printf("\n \n queue: ");
fr=q->front;
i=queuelength(q);
for(j=0;j<i;j++)
{ printf("%c",q->base[fr]);
fr=(fr+1)%maxsize;
}
#include <stdio.h>
#define NULL 0
typedef struct lnode
{
int data;
struct lnode *next;
} linklist;
linklist *create(void)
{
linklist *head,*p1,*p2;
int n;
n=0;
p1=p2=(linklist *)malloc(sizeof(linklist));
return p;
}
}
int queuelength(queue *q)
{ return(q->rear-q->front+maxsize)%maxsize;
}
void rudui(queue *q , queuetype e)
{ if( (q->rear+1) % maxsize == q->front )
for(i=0;i<6;i++) printf("%c",array[i]);
for(i=0;i<6;i++)
rudui(&queue1,array[i]);
print(&queue1);
printf("\n \n how many characters to delete: ");
scanf("%d",&t);
p1=head;p0=stud;
if(head==NULL)
{ head=p0;
p0->next=NULL;
}
else
{ while ((p0->data>p1->data)&&(p1->next!=NULL))
{ p2=p1;
p1=p1->next;
}
if(p0->data<p1->data)
{ if(head==p1) head=p0;
if( (queuelength(&queue1)<t ) ||t<1 )
printf(" \n \n input error !");
else
{ for(i=0;i<t;i++)
chudui(&queue1);
print(&queue1);
}
}
}
}
void chudui(queue *q)
{ queuetype e;
if(q->front != q->rear)
{ e=q->base[q->front];
q->front=(q->front+1)%maxsize;
printf("\n \n %c chudui chenggon ",e);
linklist *stud;
head=create();
prinf(head);
printf("\n Input a data to insert: ");
stud=(linklist *)malloc(sizeof(linklist));
scanf("%d",&stud->data);
insert(head,stud);
{ printf(" \n \n the queue if full !");
}
else
{ q->base[q->rear]=e;
q->rear=(q->rear+1) % maxsize;
printf("\n\n rear = %d ",q->rear);
printf("\n %c rudui chenggon ",e);
return head;
} }
void prinf(linklist * head)
{ linklist *p;
p=head;
while(p!=NULL)
{ printf("%5d",p->data);
p=p->next;
}
printf("\n");
}
void main()
{
int x,y,t;
linklist *head=NULL;
printf("\\n input datas:");
scanf("%d",&p1->data);
head=NULL;
while (p1->data!=0)
{
n=n+1;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(linklist *) malloc(sizeof(linklist));
scanf("%d",&p1->data);
}
p2->next=NULL;
return head;
}
void chaxun(linklist *head,int x)
{
linklist *p1=head;
int i=0;
while(p1->data!=x&&p1!=NULL)
{
p1=p1->next;
else p2->next=p0;
p0->next=p1;
}
else
{ p1->next=p0;
p0->next=NULL;
}
}
return head;
}
linklist *del(linklist *head,int num)
{
linklist *p1,*p2;
if(head==NULL)
{printf("\n listnull!\n");
{ queue *p=q;
p->base=(queuetype *)malloc(maxsize*sizeof(queuetype));
if(!p->base)
{printf("\n \n overflow");
return 0;
}
else
{ p->front=0;
p->rear=p->front;
相关主题