Stacks and queues--judgment stack/queue is empty/full __ data structure

Source: Internet
Author: User

Array Stacks
Complete the int isempty (stack S) function, which determines whether the stack is empty and returns 0 if NULL returns 1.
Complete the int isfull (stack S) function, which determines whether the stack is full and returns 0 if full returns 1.

typedef int ELEMTYPE;
struct Stackrecord;
typedef struct STACKRECORD *stack;
struct Stackrecord
{
    int Capacity;//stack capacity
    int top;//Stack tops, initially 1
    elemtype *array;
};

int IsEmpty (Stack S)
{
    if (s‐>top==‐1)
    {return
        1;
    } 
    else
    {return
        0;
    }
}
int Isfull (Stack S)
{
    if (s‐>top==s‐>capacity‐1)
    {return
        1;
    } 
    else
    {return
        0;
    }
}

Chain Stacks
Complete the int isempty (stack s) function, which determines whether stack s is empty, empty stack returns 1, or 0, known S is the chain stack of leading nodes.

typedef int ELEMTYPE;
struct Node;
typedef struct NODE * PTRTONODE;
typedef ptrtonode Stack;
struct Node
{
    elemtype data;
    Ptrtonode Next;

int IsEmpty (Stack S)
{return
    s‐>next==null?1:0;
}

array Queues
completes the int isempty (queue q) function, which determines whether the queue Q is empty, returns 0 if it is empty, or 1, where Q is an array-based, non-circular queue.
Complete the int isfull (queue q) function, which determines whether the queue Q is full and returns 0 if the full returns 1, where q is an array-based, non-circular queue.

typedef int ELEMTYPE;
struct Queuerecord;
typedef struct QUEUERECORD * QUEUE;
struct Queuerecord
{
    int Capacity;//Queue Total capacity
    int Front;//Team First initial value is 0
    int rear;//team tail, initial value is 1
    int Size;// The number of data in the queue, the initial value is 0
    elemtype *array;

int IsEmpty (Queue Q)
{return
    q‐>size==0;
}
int Isfull (Queue Q)
{return
    q‐>rear==q‐>capacity‐1?1:0;
}

Chain Queues
Complete the int isempty (queue q) function, which determines whether the queue Q based on the linked list is empty, the empty queue returns 1, and the Non-empty queue returns 0, where Q is a linked list queue that does not lead the node.

typedef int elemtype; struct node; typedef struct node node; struct queue; typedef struct Queue *
Queue;
    struct Node {elemtype data;
Node * NEXT;
};

struct Queue {node * Front/Team First Node * rear;//team tail int size;//queue data}; int IsEmpty (Queue q) {return q‐>size==0?1:0;} 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.