C Language/c++ Programming Learning: An array scheme for code implementation of stacks

Source: Internet
Author: User

C language is process-oriented, and C + + is Object-oriented

The difference between C and C + +:

C is a structured language that focuses on algorithms and data structures. The design of the C program is primarily concerned with the output (or implementation process (transaction) control) of the input (or environmental conditions) that is processed through a process.

C + +, the first consideration is how to construct an object model, so that the model can fit with the corresponding problem domain, so that you can get the state information of the object to get output or implementation process (transaction) control. So the biggest difference between C and C + + is that their way of thinking about solving problems is different. C + + is more advanced than C because "the concept of design has been incorporated into C + +".

The biggest difference between C and C + + is that their way of thinking is different for solving problems. The reason that C + + is more advanced than C is because "the concept of design has been incorporated into C + +", and in terms of language itself, in C more is the concept of algorithms. Then C is not important, wrong! Algorithm is the basis of programming, good design if there is no good algorithm, just as not. Moreover, "C plus good design" can also write very good things.

Stack is a kind of data structure which has the feature of "advanced after out" from macroscopic point of view. Can be implemented by arrays or linked lists.

Its implementation is done from the "one end" operation, resulting in the first stored data is finally taken out. Has the stack top, the stack bottom and so on factor composition. : Stack of code implementation of the array scheme, the memory of the implementation of the principle of the stack in detail. This is only understood in the macro, and how the relevant code is implemented.

Its structure type is:

#define N 30

struct _stack

{

int top;

int data[n];

};

typedef struct _STACK Mystack;

The operation of the stack usually has the initialization, the judgment stack empty, the stack fills, the stack, the operation, empties and so on operation. Here are the separate implementations:

Small series recommended a learning C language/c++ study Skirt "730, 130, 221", whether you are Daniel or small white, is to change careers or want to join the study together to learn about progress together! The skirt has the development tool, many dry goods and the technical information to share!

Small series recommended a learning C language/c++ study Skirt "730, 130, 221", whether you are Daniel or small white, is to change careers or want to join the study together to learn about progress together! The skirt has the development tool, many dry goods and the technical information to share!

Calling code:

int main () {

Mystack MS;

Init (&MS);

int flag = 0;

int value = 0;

Value = 0;

Flag = Push (&ms, value);

if (flag)

{

printf ("%d into stack success", value);

}

Else

{

printf ("%d failed in stack", value);

}

Value = 1;

Flag = Push (&ms, value);

if (flag)

{

printf ("%d into stack success", value);

}

Else

{

printf ("%d failed in stack", value);

}

Value = 2;

Flag = Push (&ms, value);

if (flag)

{

printf ("%d into stack success", value);

}

Else

{

printf ("%d failed in stack", value);

}

Show (&MS);

Pop-up stack

int output_value = 0;

int output_flag = 0;

Output_flag = Pop (&ms, &output_value);

if (Output_flag)

{

printf ("Out of stack success, data out of stack:%d", output_value);

}

Else

{

printf ("Failed out of stack");

}

Output_flag = Pop (&ms, &output_value);

if (Output_flag)

{

printf ("Out of stack success, data out of stack:%d", output_value);

}

Else

{

printf ("Failed out of stack");

}

Output_flag = Pop (&ms, &output_value);

if (Output_flag)

{

printf ("Out of stack success, data out of stack:%d", output_value);

}

Else

{

printf ("Failed out of stack");

}

Show (&MS);

System ("pause");

return 0;

}

Test results:

Small series recommended a learning C language/c++ study Skirt "730, 130, 221", whether you are Daniel or small white, is to change careers or want to join the study together to learn about progress together! The skirt has the development tool, many dry goods and the technical information to share!

These are the things that C + + can do

Server Development Engineer, AI, cloud computing engineer, information security (hacker anti-hacker), big data, data platform, embedded engineer, streaming media server, Data control solution, image processing, audio and video development engineer, game server, distributed system, game assistant, etc.

C Language/c++ Programming Learning: An array scheme for code implementation of stacks

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.