C pointer programming path-fifth note

Source: Internet
Author: User

C pointer programming path-fifth note
// Pointer application in Data Structure
// The Difference Between the stack in the memory and the stack roommate in the Data Structure
// In the data structure, the stack is often put together to represent a data structure,
// But in the memory, the heap stores dynamic memory, and the stack stores static and called functions.
// The data structure involves stacks, queues, and linked lists. Here, queues are mainly implemented.
// Pointer application of the cyclic queue
# Include
# Include
# Define QueueSize_UarLen 8
Using namespace std;
Typedef struct
{
Int front;
Int rear;
Int counter;
Int uart_data [QueueSize_UartLen];
} CIRQUEUE_UART;


// Queue Initialization
Void InitQueue (CIRQUEUE_UART * queue)
{
Queue-> front = 0;
Queue-> rear = 0;
Queue-> counter = 0;
}


// Enter the team
Int InQueue (CIRQUEUE_UART * queue, int data)
{
If (QueueFull (queue ))
{
// The output queue is full.
Return 0;
}
Else
{
Queue-> uart_data [queue-> rear] = data;
Queue-> counter ++;
Queue-> rear = (queue-> rear + 1) % QueueSize_UartLen;
// The previous sentence here is equivalent
// If (queue- //{
// Queue_rear = 0;
//}
// Else
//{
// Queue-> rear ++;
//}
Return 1;
}
}


// Team out
Int OutQueue (CIRQUEUE_UART * queue, int * p_data)
{
If (QueueEmpty (queue ))
{
// Output the empty queue prompt
// Return 0;
} Else
{
* P_data = queue-> data (font );
Queue-> counter --;
Queue-> front = (queue-> front + 1) % QueueSize_UartLen;
Return 1;
}


}




// Determine whether the queue is empty
Int QueueEmpty (QueueSize_UartLen * queue)
{
Return queue-> counter = 0;
}


// Determine whether it is full
Int QueueFull (QueueSize_UartLen * queue)
{
Return queue-> counter = QueueSize_UartLen;
}


Int main ()
{
/**
*
*/

}


// Tree of the C world
// Three traversal methods of Binary Trees are written here.
# Include
# Include
Typedef struct tree_node
{
Char data;
Struct tree_node * lchild, * rchild;


} BT_Node;




# Define Tree_NodeLen sizeof (BT_Node)
BT_Node * tree;
BT_Node * Creat_BTree (BT_Node * t );
Void visit_Node (BT_Node * tree );
Void Pre_Order (BT_Node * tree );
Void Mid_Order (BT_Node * tree );
Void After_Order (BT_Node * tree );


Int main ()
{
Printf ("\ n enter the node \ n ");
Tree = Creat_BTree (Tree );
If (tree)
{
Printf ("\ n forward traversal \ n ");
Pre_Order (tree );
Printf ("\ n ");


Printf ("\ n sequential traversal \ n ");
Mid_Oder (tree );
Printf ("\ n ");

Printf ("\ n sequential traversal \ n ");
After_Order (tree );
Printf ("\ n ");
}
Printf ("\ n ");
Return 0;
}


BT_Node * Create_BTree (BT_Node * tree)
{
Char ch;
Ch = getchar ();
If (ch = '*')
{
Tree = null;
}
Else
{
Tree = (BT_Node *) malloc (Tree_NodeLen );
Tree-> data = ch;
Tree-> lchild = Create_BTree (tree-> lchild );
Tree-> rchild = Create_BTree (tree-> rchild );
}
Return (tree );
}


Void Visited_Node (BT_Node * tree)
{
Printf ("");
Putchar (tree-> data );
Printf ("\ t ");
}


Void Pre_Order (BT_Node * tree)
{
If (! Tree)
{
Return;
}
Else
{
Visit_Node (tree );
Pre_Order (tree-> lchild );
Pre_Order (tree-> rchild );
}
}




Void Mid_Order (BT_Node * tree)
{
If (! Tree)
{
Return;
}
Else
{
Mid_Order (tree-> lchild );
Visit_Node (tree );
Mid_Order (tree-> rchild );
}
}


Void After_Order (BT_Node * tree)
{
If (! Tree)
{
Return;


}
Else
{
After_Order (tree-> lchild );
After_Order (tree-> rchild );
Visited_Node (tree );
}


}


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.