Stack row editing

Source: Internet
Author: User


# Include <stdio. h>
# Include <string. h>
# Include <conio. h>
# Include <stdlib. h>
# Define STACK_INIT_SIZE 50
# Define OK 1
# Define TRUE 1
# Define FALSE 0
# Define ERROR 0
# Define ESC 27
Typedef char ElemType;
Typedef struct STACK/* define STACK type */
{
ElemType * base;
ElemType * top;
Int stacksize;
Int length;
} SqStack, * Stack;
Typedef int Status;
Void InitStack (Stack * S)/* initialize Stack */
{
* S = (SqStack *) malloc (sizeof (SqStack ));
(* S)-> base = (ElemType *) malloc (STACK_INIT_SIZE * sizeof (ElemType ));
If (! (* S)-> base) exit (-1 );
(* S)-> top = (* S)-> base;
(* S)-> stacksize = STACK_INIT_SIZE;
(* S)-> length = 0;
}
Status DestroyStack (Stack * S)/* destroy Stack */
{
Free (* S)-> base );
Free (* S ));
Return OK;
}
Void ClearStack (Stack * S)/* empty Stack */
{
(* S)-> top = (* S)-> base;
(* S)-> length = 0;
}
Status StackEmpty (SqStack S)/* determine whether the stack is empty */
{
If (S. top = S. base) return TRUE;
Else
Return FALSE;
}
Void Push (Stack * S, ElemType e)/* Push data to Stack */
{
If (* S)-> top-(* S)-> base> = (* S)-> stacksize)
{
(* S)-> base = (ElemType *) realloc (* S)-> base,
(* S)-> stacksize + 10) * sizeof (ElemType ));
If (! (* S)-> base) exit (-1 );
(* S)-> top = (* S)-> base + (* S)-> stacksize;
(* S)-> stacksize + = 10;
}
* (* S)-> top ++) = e;
++ (* S)-> length;
}
Status Pop (Stack * S, ElemType * e)/* Delete the top element of the Stack */
{
If (* S)-> top = (* S)-> base) return ERROR;
* E = * (* S)-> top-1 );
-- (* S)-> length;
(* S)-> top --;
Return OK;
}
Void LineEdit ()
{Stack S;
FILE * fp;
Char ch, c, a [50];
Int I, B;
InitStack (& S);/* construct an empty stack for the buffer zone */
Fp = fopen ("wenjian. c", "w ");
If (! Fp)
{Printf ("cannot"); exit (0 );}
Ch = getchar ();
While (ch! = 'Q ')
{While (ch! = 'Q' & ch! = 'N') <

Related Article

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.