第四周学习进度

#include <stdio.h>
#include <stdlib.h>

typedef struct Node
{
    int data;
    struct Node *next;
}linkNode;

typedef struct 
{
   linkNode *front;
   linkNode *rear;
}linkqueue;

int InitLinkQueue(linkqueue *Q)
{
    Q->front=(linkNode *)malloc(sizeof(linkNode));
    if(Q->front!=NULL)
    {
        Q->rear=Q->front;
        Q->front->next=NULL;
        return 1;
    }
    else
        return 0;
 } 
 
void PushQueue(linkqueue *Q,int x)
 {
     linkNode *i;
     i=(linkNode *)malloc(sizeof(linkNode));
     if(i!=NULL)
     {
         i->data=x;
         i->next=NULL;
         Q->rear->next=i;
         Q->rear=i;
         return(1);
     }
     else return(0);//溢出
 }

int PopQueue(linkqueue *Q,int *x)
{
    linkNode *p;
    if(Q->front==Q->rear) return 0;//判空
    p=Q->front->next;
    Q->front->next=p->next;
    if(Q->rear==p)
      Q->rear=Q->front;
    *x=p->data;
    free(p);
    return 1;
}

int main(int argc, char *argv[]) 
{
    linkqueue Q; 
    int x,y;
    InitLinkQueue(&Q);
    printf("请输入-1结束\n");
    scanf("%d",&x);
    while(x!=-1)
    {
        PushQueue(&Q,x);
        scanf("%d",&x);
    } 
    while(Q.rear!=Q.front)
    {
        PopQueue(&Q,&y);
        printf("%d\n",y);
    }
    return 0;
}
#include <stdio.h>
#include <stdlib.h>

typedef struct Node
{
    int data;
    struct Node *next;
}stackNode,*linkstack;

void InitLinkStack(linkstack *top)
{
    *top=(linkstack)malloc(sizeof(stackNode));
    (*top)->next=NULL;
}

void PushStack(linkstack top,int x)
{
    linkstack s;
    s=(stackNode*)malloc(sizeof(stackNode));
    s->data=x;
    s->next=top->next;
    top->next=s;     
}
int PopStack(linkstack top,int *x)
{
    linkstack s;
    s=top->next;
    if(s==NULL)
        return 0;
    *x=s->data;
    top->next=s->next;
    free(s);
    return 1;
}

int main(int argc, char *argv[]) 
{
    linkstack top;
    int x,y;
    InitLinkStack(&top);
    printf("请输入-1结束\n");
    scanf("%d",&x);
    while(x!=-1)
    {
        PushStack(top,x);
        scanf("%d",&x);
    }
    while(top->next!=NULL)
    {
        PopStack(top,&y);
        printf("%d\n",y);
    }
    return 0;
}
#include <stdio.h>
#include <stdlib.h>
#define maxsize 100

typedef struct sq
{
    int elem[maxsize]; 
    int front;
    int rear;    
}seqqueue;

void InitSeqQueue(seqqueue *Q)
{
    Q->front=Q->rear=0;
}

int PushSeqQueue(seqqueue *Q,int x)
{
    if ((Q->rear+1)%maxsize==Q->front  )
        return 0;
    Q->elem[Q->rear]=x;
    Q->rear=(Q->rear+1)%maxsize;
    return 1;
}

int PopSeqQueue(seqqueue *Q,int *x)
{
    if ( Q->front==Q->rear )
        return 0;
    *x=Q->elem[Q->front];
    Q->front=(Q->front+1)%maxsize;
}

int main(int argc, char *argv[]) 
{
    seqqueue Q;
    int x,y;
    InitSeqQueue(&Q);
    printf("请输入0结束\n");
    scanf("%d",&x);
    while(x!=0)
    {
        PushSeqQueue(&Q,x);
        scanf("%d",&x);
    }
    while(Q.front!=Q.rear)
    {
        PopSeqQueue(&Q,&y);
        printf("%d\n",y);
    }
    return 0;
}
#include <stdio.h>
#include <stdlib.h>
#define stack_size 20

typedef struct stack
{
    int elem[stack_size];
    int top;
}seqstack;

void InitStack(seqstack *S)
{
    S->top=0;
} 

int PushStack(seqstack *S,int x)
{
    if (S->top==stack_size-1 )return 0;
    S->top++;
    S->elem[S->top]=x;
    return 0;
}
 
int PopStack(seqstack *S,int *x)
{  
    if (S->top==0 ) 
        return 0; 
     *x=S->elem[S->top];
    S->top--;
     return 1;
}

int main(int argc, char *argv[]) 
{
    int x,y;
    seqstack S;
    InitStack(&S); 
    printf("请输入0结束 \n");
    scanf("%d",&x);
    while (x!=0)
    {
        PushStack(&S,x);
         scanf("%d",&x);
    } 
    while(S.top!=0)
    {
        PopStack(&S,&y);
        printf("%d\n",y);
    }
    return 0;
}

 

日期 学习方法 学习时间 新增代码行 知识总结
星期一 看慕课视频 1.5h 0  
星期二        
星期三 看慕课视频 2h 0  
星期四 看课堂视频回放 2h 0  
星期五 看慕课视频 1h 100  
星期六        
星期日 做实验练习 1.5h 70  
总计 看视频、做练习 8h 170  
posted @ 2020-05-17 20:10  VousAime  阅读(160)  评论(0)    收藏  举报