指针-跪求大神 c++词频 排序

问题描述

跪求大神 c++词频 排序

You say that you love rain,
but you open your umbrella when it rains.
You say that you love the sun,
but you find a shadow spot when the sun shines.
You say that you love the wind,
but you close your windows when wind blows.
This is why I am afraid,
because you say that you love me too。
将上述文字 利用c++堆栈 指针 或者数据库 进行词频统计
以及词频大小排序

解决方案

一、实验目的

设计并实现链表、栈、队列基本操作,为编译原理的学习打下基础。

二、实验要求

实现线性表、栈、队列创建、查找、插入、删除等基本操作。

三、实验步骤

1.参考数据结构

//结点

typedef struct{

struct Node *next;

    struct Node *pre;

int data;

}Node;

//链表头结点

struct

{

struct Node* head;

struct Node* tail;

int count;

} List;

typedef List Stack;//使用链表作为堆栈的底层实现结构

typedef List Queue;//使用链表作为队列的底层实现结构

2.操作

2.1 表

2.1.1. 初始化

void list_init(struct List* root){

    root->count = 0;

root->head = NULL;

root->tail = NULL;

}

2.1.2 插入

//插入到队列末尾

void push_back(Node* node, List* list){

if(list->head == NULL){//如果list头结点为空

            list->head = list->tail = node;

            node->next = node->pre = NULL;               

            list->count++;

            return;

    }

    node->next = NULL;

    node->pre = list->tail;

    list->tail->next = node;

    list->tail = node;

    list->count++;

}

//插入到队列头部

void push_front(Node node, List list){

    if(list->head == NULL){

            list->head = list->tail = node;

            node->next = node->pre = NULL;               

            list->count++;

            return;

    }

    node->pre= NULL;

    node->next = list->head;

    list->head->pre = node;

    list->head = node;

    list->count++;

}

//插入到位置locate

int insert(Node *node, List *list, int locate){

    //异常处理

if(locate > list->count || locate < 0)return -1;

    //插入到头部

    if(locate == 0){push_front(node, list); return 1;}

    //插入到尾部

if(locate == list->count){push_back(node, list); return 1;}

    //其它

    int curValue = -1;

    //查找并插入到cur的前面

    Node *cur = list->head;

    while(++curValue < locate)cur = cur->next;

    //插入

    node->next = cur;

    node->pre = cur->pre;       

    cur->pre->next = node;

    cur->pre = node;

//容量加1

list->count++;

    return 1;

}

2.1.3 查找

Node* search(Node *node, List *list, int &locate){

//返回相应的头结点,并记录该结点的位置到locate中

    locate = 0;

    Node *cur = list->head;

    while(cur != NULL && cur->data != node->data){cur = cur->next; locate++;}

    if(cur == NULL) locate = - 1;

    return cur;

}

2.1.4. 删除

int remove(List *list, int locate){

    //异常

    if(locate >= list->count || locate < 0)return -1;

    if(locate == 0){//头部

            Node *p = list->head->next;       

            free(list->head);

            p->pre = NULL;

            list->head = p;               

    } else if(locate == list->count - 1){//尾部

            Node *p = list->tail->pre;               

            free(list->tail);

            p->next = NULL;

            list->tail = p;               

    } else{//其它

            //查找并保存到cur中

int curValue = -1;

            Node *cur = list->head;

            while(++curValue < locate)cur = cur->next;

            cur->pre->next = cur->next;

            cur->next->pre = cur->pre;

            free(cur);

    }

list->count--;

    return 1;

}

2.2. 堆栈操作

2.2.1 初始化

void stack_init(Stack *s){

    list_init((List*)s);

}

2.2.2 压栈

void push(struct Node* node, Stack* s){

    push_front(node, (List*)s);

}

2.2.3 出栈

Node* pop(Stack* s){

    Node *node = s->head;

    if(s->head->next != NULL)

            s->head = s->head->next;

    return node;

}

2.2.4 获得栈顶

Node* get_top_stack(struct Node* node, Stack* s){

    return s->head;

}

2.3. 堆栈操作

2.3.1. 初始化队列

void queue_init(Queue *q){

    list_init((List*)q);

}

2.3.2. 入队列

void in_queue(struct Node* node, Queue* q){

    push_back(node, (List*)q);

}

2.3.3. 出队列

Node* out_queue(Queue* q){

    Node *node = q->head;

    if(q->head->next != NULL)

            q->head = q->head->next;

    return node;

}

2.3.4. 获得队列头

Node* get_first_queue(struct Node* node, Queue* q){

    return q->head;

}

解决方案二:

可以利用上面的东西。。

解决方案三:

君乐雨兮启兰枝,君乐日兮林蔽日
君乐风兮兰帐起,君乐吾兮吾心噬

解决方案四:

考虑下快速排序qsort

时间: 2024-09-20 06:03:09

指针-跪求大神 c++词频 排序的相关文章

hdu1716 排序 oj-HDU 1716排列2 老是PE,跪求大神指点

问题描述 HDU 1716排列2 老是PE,跪求大神指点 #include #include using namespace std; int main(){ int a[4]; int flag=0; while(cin>>a[0]>>a[1]>>a[2]>>a[3]&&a[0]+a[1]+a[2]+a[3]!=0){ sort(a,a+4); int flag2 = 0; do{ if(a[0]==0) continue; static

Science上发表的聚类算法,C++编程实现,有一个bug不知道怎么解决!!跪求大神!!!

问题描述 Science上发表的聚类算法,C++编程实现,有一个bug不知道怎么解决!!跪求大神!!! include<iostream> include<fstream>using namespace std; typedef struct sourcedata //声明了一个原始数据结构体 { int m; //矩阵的行rows int n; //矩阵的列columns double **data; //保存数据的二维指针 }SourceData; SourceData get

跪求大神给一个sql分类汇总语句

问题描述 跪求大神给一个sql分类汇总语句 10C 现有两张表:Dept:ID DName ParentDept1 总经办 02 行政部 13 企划部 1Leave:ID UserName Udept Uposition Lstart Lend Lstatus Lstype 1 张三 2 科员 2015-06-09 2015-06-10 2 12 李四 3 职员 2015-06-22 2015-06-25 3 23 王五 2 职员 2015-05-19 2015-05-22 3 2要求先按照Ud

c语言-关于C语言链表的一些问题,代码怎么都运行不成功跪求大神指点

问题描述 关于C语言链表的一些问题,代码怎么都运行不成功跪求大神指点 下面代码主要实现链表的创建,插入,删除,并且能将两个年龄递增链表进行合并成递减链表 然而在插入和删除操作中gets函数无法起作用,strcmp函数也出现位置冲突报错..功力不足实在解决不了..跪求大神解答..(感觉自己写的东西除了上面两个错误应该还有,但是因为位置冲突问题就只能编译到那个地方无法进行下去..我肉眼实在找不出来.. #include<stdio.h> #include<stdlib.h> #incl

fortran-关于FORTRAN调用matlab出现问题,无从下手,跪求大神指点!

问题描述 关于FORTRAN调用matlab出现问题,无从下手,跪求大神指点! 首先说明,我用的是VS2008平台,intel fortran安装在该平台下,matlab为2010a版本 .调用了matlab中的libeng.lib libmat.lib libmex.lib libmx.lib库文件.程序可以编译,但是运行时候出错.代码 !!matlab函数调用模块 !!!!! module matlab implicit none integer ep !指针,用于指向打开的matlab i

vs2012+matlab2013-VS2012调用matlab2013出现问题。跪求大神指导啊

问题描述 VS2012调用matlab2013出现问题.跪求大神指导啊 函数代码: int main(int argc, char argv[]) { QApplication a(argc, argv); loSmoothing w; w.show(); Engine *ep; //定义matlab引擎指针 if (!(ep=engOpen(NULL))) //测试是否启动Matlab引擎成功. { cout <<"Can't start Matlab engine!"

为什么getgarphics()返回空指针?跪求大神(怎么木有人来?新人第一贴啊,加到最高分了啊啊啊)

问题描述 看过一些帖子里说在FramesetVisible之前获取Graphics对象,会得到null,但是查阅API发现这段话:创建供绘制闭屏图像(off-screenimage)使用的图形上下文.此方法仅供闭屏图像调用.其中图形上下文字的就是graphics了?那么闭屏图像是指非可视化的图像?这不就和上述的visible矛盾了么?这是一个问题,下附代码(不用全看,后有解释,其后还有些小问题)跪求大神(望浅显易懂,本人非科班出生,刚自学一星期):publicclassBreakOutexten

net-登陆密码错误 数据库里的用户和密码明明都是对的 怎么破怎么破 跪求大神帮助

问题描述 登陆密码错误 数据库里的用户和密码明明都是对的 怎么破怎么破 跪求大神帮助 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Web.Bll; using Web.Mod; public partial class _Default : System

二叉树 求结点个数-c++编程,,跪求大神解答

问题描述 c++编程,,跪求大神解答 #include using namespace std; template struct BiNode { BiNode *lchild; datatype data; BiNode *rchild; }; template struct element { BiNode *ptr; int flag; }; BiNode *first,*bt,*q,*temp,stack[20],queue[20]; element s[20]; int count=0