博文

练习:用栈实现逆序输出26个字母(2006-05-13 12:10:00)

摘要://实现栈类
//逆序输出26个字母
//2006 05 13
#include <iostream.h>
#include<string>

class Node{
public:
    char data;
    Node *next;
};
class Stack:public Node{
    Node *Bottom;
    Node *Top;
    int SLen;
public:
    void InitStack();
    char Pop();
    void Push(char e);
    bool StackEmpty();
};

void Stack::InitStack()
{
    Top=new Node;
    Bottom=Top;
    SLen=0;
}
char Stack::Pop()
{
    char e;
    Node *p;
    if(!(Top->next))
        ......

阅读全文(2646) | 评论:0

练习:用栈检测表达式括弧匹配(2006-05-13 12:02:00)

摘要:/1、实现栈类
//2、检测表达式括弧匹配
//2006 05 13
#include <iostream.h>
#include<string>

class Node{
public:
    int data;
    Node *next;
};
class Stack:public Node{
    Node *Bottom;
    Node *Top;
    int SLen;
public:
    void InitStack();
    char Pop();
    void Push(int e);
    bool StackEmpty();
};

void Stack::InitStack()
{
    Top=new Node;
    Bottom=Top;
    SLen=0;
}
char Stack::Pop()
{
    char e;
    Node *p;
    if(!(Top->next))
       &nbs......

阅读全文(2360) | 评论:0

练习:用栈实现10进制到8进制的转换(2006-05-13 11:59:00)

摘要://1、实现栈类
//2、实现10进制到8进制的转换
//2006 05 13
#include <iostream.h>
#include<string>

class Node{
public:
    int data;
    Node *next;
};
class Stack:public Node{
    Node *Bottom;
    Node *Top;
    int SLen;
public:
    void InitStack();
    int Pop();
    void Push(int e);
    bool StackEmpty();
};

void Stack::InitStack()
{
    Top=new Node;
    Bottom=Top;
    SLen=0;
}
int Stack::Pop()
{
    int e;
    Node *p;
    if(!(Top->next))
       &n......

阅读全文(2836) | 评论:0

练习:KMP算法 字符串匹配(2006-05-08 00:16:00)

摘要://
//字符串模式匹配:KMP算法
//
//06.05.07 vc6.0调试通过
//ZYQ
//
#include <iostream.h>
#include <string>

int* get_next(char *T);

void main()
{
    char* s="hhhsauhduwdh";
    char* t="hdu";
    int i=0;
    int j=0;
    int S=strlen(s);
    int T=strlen(t);
    int *next=get_next(t);
    while(i<S&&j<T)
    {//判定条件i<S&&j<T说明:字符串数组下标从0开始,到字符串长度减1结束
        if(j==0||s[i]==t[j])
        {i++;j++;}//继续向后比较字符
        else
            j=next[j];//模式串向后移......

阅读全文(4931) | 评论:3

练习:字符串首尾模式匹配(2006-05-06 20:50:00)

摘要://字符串首尾模式匹配

#include <iostream.h>
#include <string>

void main()
{
    char* s="hhhsauhduwdh";
    char* t="sau";
    int i=0;
    int j=0;
    int Slen=strlen(s);
    int Tlen=strlen(t);
    while(i<=Slen-Tlen+1)
    {//
        if(s[i]!=t[0]){i++;}
        else if(s[i]==t[0]&&s[i+Tlen-1]!=t[Tlen-1]){i++;}
        else 
        {
            int k=1;
            j=1;
   &nbs......

阅读全文(2804) | 评论:0

练习:简单模式字符串匹配(2006-05-06 20:47:00)

摘要://
//字符串模式匹配:简单模式下的匹配
//用于串的定长顺序结构表示
//
#include <iostream.h>
#include <string>

void main()
{
    char* s="hhhsauhduwdh";
    char* t="sau";
    int i=0;
    int j=0;
    int S=strlen(s);
    int T=strlen(t);
    while(i<S&&j<T)
    {//判定条件i<S&&j<T说明:字符串数组下标从0开始,到字符串长度减1结束
        if(s[i]==t[j]){i++;j++;}
        else {i=i-j+2;j=1;}
    }
    if(j>=T)
        cout<<i-T<<endl;
    else
        cout<<"0"<......

阅读全文(2817) | 评论:0