AutoCAD 3DMAX C语言 Pro/E UG JAVA编程 PHP编程 Maya动画 Matlab应用 Android
Photoshop Word Excel flash VB编程 VC编程 Coreldraw SolidWorks A Designer Unity3D
 首页 > 数据结构

链表基本操作的程序实现

51自学网 2015-09-08 http://www.51zixue.net

 

#include"head_node.h"

/**********************************/
/*         删除重复               */
/**********************************/

void Delete_Repeat_Node(node *head)
{
    node *p,*pre,*s;
    pre=head->next;
    p=pre->next;
    while(p)
    {
        s=p->next;
        while(s&&s->info!=p->info)
        {
            s=s->next;
        }
        if(s)
        {
            pre->next=p->next;
            free(p);
            p=pre->next;
        }
        else
        {
            pre=p;
            p=p->next;
        }
    }
}

int main()
{
    node *head;
    head=Creat_Node();
    Print_Node(head);
    Delete_Repeat_Node(head);
    Print_Node(head);
    return 0;
}

 

#include"Head_Node.h"
/************************************/
/*           在Y前插入X             */
/************************************/
void Before_y_Insert_x(node* head,int y,int x)
{
    node *pre,*p,*s;
    pre=head;
    p=pre->next;
    while(p&&p->info!=y)
    {
        pre=p;
        p=p->next;
    }
    if(p==NULL)
    {
        printf("error!%d不在该链表中/n",y);
    }
    else
    {
        s=(node*)malloc(sizeof(node));
        s->info=x;
        s->next=p;
        pre->next=s;
    }
}

int main()
{
    node *head;
    int x,y;
    head=Creat_Node();
    printf("在y前插入x,输入y,x:");
    scanf("%d%d",&y,&x);
    Print_Node(head);
    Before_y_Insert_x(head,y,x);
    Print_Node(head);
    return 0;
}

 
 

上一篇:无向图转换&遍历&MST  下一篇:有向图转换&遍历&拓扑&最短路径