⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zfqzuoyeq.c

📁 数据结构中关于树、栈、队列等数据结构的一些算法的C语言实现
💻 C
字号:
#include <stdio.h>
struct stack 
{
    int data ;
    struct stack*next ;
};
struct stack *top=NULL ;
void reverse()                       /*串的倒置*/
{
    char s[50],t[50];
    int i=0,j ;
    printf("input strings\n");
    scanf("%s",s);
    while(s[i]!='\0')
    {
        i++;
    }
    i--;
    for(j=0;i!=0;i--,j++)
    t[j]=s[i];
    t[j]=s[i];
    printf("result:%s\n",t);
}

void connect()                    /*两个串的连接*/
{
    char r[50],s[50],t[100];
    int i,j ;
    printf("input s1 and s2\n");
    scanf("%s",r);
    scanf("%s",s);
    for(i=0;r[i]!='\0';i++)
    t[i]=r[i];
    for(j=0;s[j]!='\0';j++,i++)
    t[i]=s[j];
    t[i]='\0' ;
    printf("result:\ns1:%s\ns2:%s\ns3:%s",r,s,t);
    
}

int pop(int*e)               /*出栈*/
{
    if(top!=NULL)
    {
        *e=top->data ;
        top=top->next ;
    }
    else 
    {
        printf("\nThere is no element");
        return(1);
    }
}
void push(int e)                   /*进栈*/
{
    struct stack*p ;
    p=(struct stack*)malloc(sizeof(struct stack));
    p->data=e ;
    p->next=top ;
    top=p ;
}

void st()
{
    char q ;
    int c,m=0 ;
    do 
    {
        printf("\ninput number element of stack: ");
        scanf("%d",&c);
        push(c);
        printf("\ndo you want to continue ? input Y/N");
        q=getch();
    }
    while(q=='y'||q=='Y');
    do 
    {
        m=pop(&c);
        if(m==1)
        return ;
        printf("\nthe top of the stack: %d",c);
        printf("\ndo you want to continue ? input Y/N");
        q=getch();
    }
    while(q=='y'||q=='Y');
}

main()
{
    reverse();
    connect();
    st();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -