心如止水
Je n'ai pas le temps
posts - 400,comments - 130,trackbacks - 0
#include<stdio.h>
#include
<stdlib.h>
struct node
{
       
int data;
       
struct node *next;
}
;//结构类型的说明

struct node *stack(struct node *head)
{
     
int i;
     
struct node *p;
     p 
= (struct node*)malloc(sizeof(struct node));
     p
->next = NULL;
     
for(i=0;i<10;i++)
       
{
         head 
= (struct node*)malloc(sizeof(struct node));
         p
->data = i;
         head
->next = p;
         p 
= head;;
       }

     
return (head);
}
//

struct node *team(struct node *head)
{
     
int i;
     
struct node *tail,*p;
     head 
= (struct node*)malloc(sizeof(struct node));
     tail 
= head;
     
for(i=0;i<10;i++)
       
{
         p 
= (struct node*)malloc(sizeof(struct node));
         p
->data = i;
         tail
->next = p;
         tail 
= p;
       }

     tail
->next = NULL;
     
return (head);
}
//队列

void print_list(struct node *head)
{
     
struct node *p;
     p 
= head->next;
     printf(
"Begin");
     
while(p != NULL)
       
{
         printf(
"->%d",p->data);
         p 
= p->next;
       }

     printf(
"->End\n");
}
//链表输出

void detele_x(struct node *head,int x)
{
     
struct node *p,*q;
     p 
= head;
     q 
= head->next;
     
while(q->data != x && q->next != NULL)
       
{ p = q; q = q->next; }
     
if(q->data == x)
       p
->next = q->next;
     free(q);
}
//删除数据域为x的结点

void add_x_y(struct node *head,int x,int y)
{
     
struct node *add_new,*p,*q;
     add_new 
= (struct node*)malloc(sizeof(struct node));
     add_new
->data = x;
     p 
= head;
     q 
= head->next;
     
while(q != NULL && q->data != y)
       
{ p = q; q = q->next; }
     p
->next = add_new;
     add_new
->next = q;
}
//在数据为y的结点前插入数据域为x的结点
posted on 2010-01-06 18:22 lee1r 阅读(200) 评论(0)  编辑 收藏 引用 所属分类: 算法与数据结构

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理