AHA algorithm-Stacks, queues, linked lists

Source: Internet
Author: User

Through the topic we can see what this article will introduce, stack, queue, linked list is essentially the data structure of the things, through this chapter of learning can give future data structure of learning to lay a foundation.

Queue:

We use a simple puzzle to introduce the concept of the queue, give a string of 9-bit encryption QQ number, for this number, delete the first digit, and then put the second digit to the end of this string of numbers. Repeat until all digits of this string of numbers are deleted. In this process, according to the number of the order to delete the sequence of 9 digits is the decrypted QQ number, what is the QQ number after decryption?

In fact, from the point of view of mathematical principles, this problem is not difficult, very good understanding, but the key is, how to use the program to efficiently calculate it?

The concept of a queue is used here. We see these 9 numbers as a sequential team with array records, with variable head and tail to record the team's first and last element behind the team (to make it easier to tell if the queue is empty, to point tail to the element behind the tail of the team), What we do with this 9-string queue is essentially the team-up and out-of-the-box, the so-called team that adds an element after the end of the squad, so-called out-of-line deletes a HEAD element. Then, based on such a simple data structure, we can do a good job of decoding the QQ number of the simulation operation.

#include <stdio.h>structqueue{intdata[ -]; inthead, tail;};intMain () {structqueue q; inti; Q.head=1; Q.tail=1;  for(i =1; I <=9; i++) {scanf ("%d",&Q.data[q.tail]); Q.tail++; }      while(Q.head <q.tail) {printf ("%d", Q.data[q.head]); Q.head++; Q.data[q.tail]=Q.data[q.head]; Q.tail++; Q.head++; }     return 0;}

AHA algorithm-Stacks, queues, linked lists

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.