Preview

数据结构C语言版_串的块链存储表示和实现

Good Essays
Open Document
Open Document
1320 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
数据结构C语言版_串的块链存储表示和实现
数据结构C语言版 串的块链存储表示和实现.txt成熟不是心变老,而是眼泪在眼里打转却还保持微笑。把一切平凡的事做好既不平凡,把一切简单的事做对既不简单。/* 数据结构C语言版 串的块链存储表示和实现 P78 编译环境:Dev-C++ 4.9.9.2 日期:2011年2月12日
*/

#include
#include
#include
#include

// LString.h 串的块链存储表示
#define CHUNKSIZE 4 // 可由用户定义的块大小

typedef struct Chunk
{
char ch[CHUNKSIZE]; //块的数据域 struct Chunk *next; //块的指针域
}Chunk;

typedef struct
{
Chunk *head, // 串的头指针 *tail; // 串的尾指针 int curlen; // 串的当前长度
}LString;

char blank = '#'; // 全局变量,用于填补空余

// 初始化(产生空串)字符串T。 void InitString(LString *T)
{
(*T).curlen=0; (*T).head=NULL; (*T).tail=NULL;
}

// 生成一个其值等于chars的串T(要求chars中不包含填补空余的字符)
// 成功返回1,否则返回0 int StrAssign(LString *T,char *chars)
{
int i,j,k,l; Chunk *p,*q; i=strlen(chars); // i为串的长度 if(!i||strchr(chars,blank)) // 串长为0或chars中包含填补空余的字符 return 0; (*T).curlen=i; j=i/CHUNKSIZE; // j为块链的结点数,块的个数 if(i%CHUNKSIZE) //不足一个块的,当成一个块即块数加1 j++; for(k=0;knext=p; q=p; } for(l=0;lch+l)=*chars++; if(!*chars) // 最后一个链块 { (*T).tail=q; q->next=NULL; for(;lch+l)=blank; } } return 1;
}

// 由串S复制得串T(连填补空余的字符一块拷贝) int StrCopy(LString *T,LString S)
{
Chunk *h=S.head,*p,*q; (*T).curlen=S.curlen; if(h) { p=(*T).head=(Chunk*)malloc(sizeof(Chunk)); *p=*h; // 复制1个结点 h=h->next; while(h) //没到队尾,继续复制块 { q=p; p=(Chunk*)malloc(sizeof(Chunk)); q->next=p; *p=*h; h=h->next; } p->next=NULL; (*T).tail=p; return 1; } else return 0;
}

// 若S为空串,则返回1,否则返回0 int StrEmpty(LString S)
{
if(S.curlen) // 非空 return 0; else return 1;
}

// 若S>T,则返回值>0;若S=T,则返回值=0;若Sch+jt)==blank) // 跳过填补空余的字符 { jt++; if(jt==CHUNKSIZE) { pt=pt->next; jt=0; } }; // *(pt->ch+jt)为T的第i个有效字符 if(*(ps->ch+js)!=*(pt->ch+jt)) return *(ps->ch+js)-*(pt->ch+jt); else // 继续比较下一个字符 { js++; if(js==CHUNKSIZE) { ps=ps->next; js=0; } jt++;

You May Also Find These Documents Helpful

  • Satisfactory Essays

    Pt1420 Unit 6 Lab Report

    • 288 Words
    • 2 Pages

    Step 6 : Break the input string into square matrices of maximum possible size of…

    • 288 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Zheng He Research Paper

    • 410 Words
    • 2 Pages

    Zheng He, originally named Ma He, was a Chinese Muslim born in 1381. At the age of ten he was taken to North China and assigned to serve Zhu Di (“Zheng He” Gale). Almost twenty years later, In 1402, Zhu Di, who was once the prince, came to be the Yongle Emperor and appointed Zheng He as an Admiral. Three years later, in 1405, after Zheng He had proven his worth, he was appointed as a commander of a fleet of “treasure ships”. At this time, the Ming dynasty was not known to the world. It was Zheng He’s job to make China known to the rest of the world. As Zheng He commanded his fleet, he explored around Asia and Africa. Furthermore, He traveled to many nations and territories, such as India, the Middle East, and Eastern Africa. Famously, Zheng He contributed to the almost complete eradication of pirates in the Southeast Asian waters and helped secure the trade routes through China and India (“Zheng He” Gale). As Zheng He explored, he created alliances with many territories and conquered any who resisted. He rose up the ranks as he helped the Ming Dynasty grow. Therefore, he was seen as a man with authority and was noted as one of the Ming Dynasty's top…

    • 410 Words
    • 2 Pages
    Good Essays
  • Good Essays

    Zheng He Research Paper

    • 533 Words
    • 3 Pages

    Was Christopher Columbus the first to discover America? Nowadays if you ask someone who was the first to discover America, most would say Christopher Columbus. But if you ask a real historian or a history professor, they would go back as far as 70 years before Columbus discovered America. Columbus may have been the first to discover America, but evidence shows that there was another man who discovered America 70 years before Columbus. This man was a 15th Chinese Admiral who lived during the Ming Dynasty and he is Zheng He. Zheng He served the Ming Dynasty Emperor, Zhu Di (Yong Le), and was leader of 7 voyages in the Indian Ocean. He visited more than 30 countries with a…

    • 533 Words
    • 3 Pages
    Good Essays
  • Good Essays

    f cannabis for himself and his many subjects. Emperor Shen Nung is considered the father of Chinese agriculture and wrote about 365 different kinds of medicine; however, cannabis was considered by him to be one of the most beneficial herbs available to mankind. In his book The Herbal, Nung talked about the therapeutic effects of cannabis and how to prepare it into medicinal form. Nung prepared the herb by consuming it in a drink made of hot water and cannabis leaves, called Ma. The drink would be prescribed to treat gout, malaria, rheumatism and issues with memory.…

    • 297 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    Recently, a farmer in China named Jia Jinglong, shot and killed a village chief with a nail gun. The government, including the village chief he killed, tore Mr. Jia's house down to create room for new development. The Chinese government executed Mr. Jia. His death spurred an plenty of conversation in the Chinese community. People across China argue that the Communist Party imposed Mr. Jia’s fate on him because it forces strict punishments on the most susceptible citizens. President Xi Jinping has been trying to promote the impression of fairness to the rural residents and members of the working urban class for four years. Despite his efforts, the public still believes that the Communist Party is protecting their own people. There are many examples…

    • 218 Words
    • 1 Page
    Satisfactory Essays
  • Powerful Essays

    China Research Paper

    • 1567 Words
    • 7 Pages

    Throughout the years, China is recognized for their huge mainland as opposed to Japan. China has more population than Japan. China has used their lands for agricultural purposes. Both countries were isolated until the 1500s when Europeans arrived. "These two Asian nations--one of the world's most populous country, the other the world's third most powerful economic entity" (Challenge China and Japan p.1). China and Japan are located in the same continent separated by islands both of them produce many export goods. China focuses in exports mainly for their workforce. "Japan was to be China's modernizing (west)" (China eyes Japan p.30). On the other hand, Japan uses their technology to boost…

    • 1567 Words
    • 7 Pages
    Powerful Essays
  • Powerful Essays

    Widget Corp., a Miami-based, 200 employee, organization has selected Miami IT Consultants to assess the organization’s information technology and informational system needs. Widget Corp. has experienced an increase in sales of 25% over the last year and has planned to update their IT needs to meet demand. The primary goal of the organization is to increase productivity by automating business processes in both their Accounting and Human Resources departments. In addition, Widget Corp. has expressed interest in optimizing internet connectivity and harness the power of the World Wide Web to expand business operations. The following report will outline Miami It Consultant’s analysis of information technology, information system and internet connectivity analysis. The report will outline recommendations in hardware, including input, output and storage devices; software recommendations, including operating system and software updates. Additional recommendations based on assessed organizational needs are reported as such. In addition, the report will include a clear cost analysis for each component and recommendation made herein.…

    • 1743 Words
    • 6 Pages
    Powerful Essays
  • Good Essays

    Censorship In China Essay

    • 1169 Words
    • 5 Pages

    Censorship is the act of suppressing ideas, words or images so as to control the information or data that people can access. Private parties or the government can participate in promoting censoring for their benefit or as a way of protecting the community, religion or even a state from blasphemy, treason or explicit content. Censorship has been there for a long time, and it can be traced to as early as 300 Ad where a censorship law was passed in China. Blocking the ideas of people is viewed as a way of controlling the political and moral life of the society. Most governments use censorship as a way of preventing any evil influence from reaching the people in society`. Censorship has both active and negative impacts on the people. Does censorship…

    • 1169 Words
    • 5 Pages
    Good Essays
  • Better Essays

    China Research Paper

    • 6214 Words
    • 25 Pages

    7. "Demographic Yearbook—Table 3: Population by sex, rate of population increase, surface area and density" (PDF). United Nations Statistics Division. 2008. Retrieved 24 September 2012…

    • 6214 Words
    • 25 Pages
    Better Essays
  • Good Essays

    The article “The hegemonic copyright regime vs the sharing copyright users of music?” by Bart Cammaerts, expands on the idea of music becoming easily accessible through via internet, which creates conflict for music producers and the industry. This conflict arises due to the lack of funds these companies receive from consumers downloading songs online for free. Ownership within the music industry is gradually decreasing, and new copyright strategies must be found or businesses and artists within the music industry will continue to lose funding and become critical. The article examines several ideals towards the current piracy issue that is living today and questions the reader how we should handle the regulation of digital content.…

    • 1024 Words
    • 5 Pages
    Good Essays
  • Good Essays

    economy opened up. With a rise in competitors Cemex in an effort to remain at the…

    • 618 Words
    • 6 Pages
    Good Essays
  • Satisfactory Essays

    As a senior in high school there can be many stressful and obstacles that you will face. There are so many things that you have to handle all at one time. You have to balance your school work, social life, and factor in having a job if that applies to you. Two of the biggest matters you have to sort out are what college do you plan to attend, if you do plan on going to college, and what you want your career to be. As someone who has been in to hands-on activities and computers I have combined those two interests into one and have come to the decision that I would like my career to be a computer technician. I have done some research about this career and have learned about what colleges are best to attend and what exactly a computer technician is and does.…

    • 622 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    Chinese Position Paper

    • 631 Words
    • 3 Pages

    Women writers of 1930s Chinese literature tackled issues on gender and family. Yuan Changying adapted her play over the famous Han dynasty folk ballad and love tragedy, Southeast Flies the Peacock. In the traditional ballad, the male protagonist, Zhong, was the son of the well off Jiao family’s widowed wife. He was matched with and married a common, but beautiful and talented lady named Lan. Although they loved each other, differences in status and family opposition forced the couple apart. There were many modern rewritings of this ancient ballad, and a few other May Fourth writers in Yuan’s era wrote adaptations that focused on Zhong and Lan’s romance. Readers of Yuan’s play may be curious as to why she chose to focus on Mother Jiao’s tragic story and her perspective as a widow and mother rather than focusing on the theme of romance. At first read, readers most likely viewed Mother Jiao as the remorseless villain. However, evidence in the play showed that Yuan focused on Mother Jiao’s viewpoint to expose the pain and suffering behind a woman due to her duties as a widowed mother in a traditional Chinese family structured over social norms.…

    • 631 Words
    • 3 Pages
    Good Essays
  • Good Essays

    Mao PDF

    • 11803 Words
    • 43 Pages

    PURPOSE. Oxidative stress in the RPE is widely accepted as a contributing factor to AMD. We…

    • 11803 Words
    • 43 Pages
    Good Essays
  • Good Essays

    Truong Nhu Tang an original member of the Viet Cong. In his 1985 memoir, reflects on the Viet Cong’s approach saying thier strategy was established on a solid basis and confirmed for the foreseeable future. He states that the goals remained to affect a withdrawal of United States from South Vietnam and to bring negotiations between the two forces and to achieve a new Southern government certain political objective would be pursued through focus on three fronts: political, military and diplomatic. He said they would simultaneously confront the enemy in the field, making use of the domestic support and gathering allies internationally not forgetting the American people themselves. This strategy was to characterize their…

    • 1080 Words
    • 5 Pages
    Good Essays