链接列表 [英] Linked Lists

查看:52
本文介绍了链接列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我必须编写一个程序,使用链接列表来打印

个独特单词,总单词数和最多来自

文本文件的常用词。除了

链接列表之外,我已经完成了相当多的工作。我没有粘贴我的代码告诉机器

字是什么,它工作正常,没有它就会更容易阅读。

下面是代码:


// ****代码从这里到下一节是好的,我不需要帮助

那里**** //

#include< stdio.h>

#include< string.h>

#include< stdlib.h>

struct list_elem {

char * word;

int count;

struct list_elem * next;

};


struct list_elem * head; / *头指针最初是NULL * /


int get_word(char *);

void add_to_list(char *);

void list_walk(void);


int unique_words,total_words;

struct list_elem * most_frequent_elem;


main(){

char word_buff [100];

while(get_word(word_buff))

add_to_list(word_buff);

list_walk();

printf(有%d个唯一单词,%d个单词总数为\ n,

unique_words,total_words);

printf(最常用的单词是<%s>使用%d次\ n,

most_frequent_elem-> word,most_frequent_elem->数);

}

// **************************

// ***********这里及以下的帮助

void add_to_list(char * word_buff){

/ * *代码搜索列表和重复单词

/ * **代码为品牌新单词创建新元素

void list_walk(){

/ * ******代码可以查看列表并收集统计数据

}


非常感谢任何帮助。


谢谢,

詹姆斯

解决方案

" Foodbank" < V8 ******** @ yahoo.com>在消息中写道

news:11 ********************** @ g14g2000cwa.googlegr oups.com ...

我必须编写一个程序,使用链接列表打印
文本文件中唯一单词,总单词和最常用单词的数量。
.... // ***********这里及以下的帮助
void add_to_list(char * word_buff){
/ * *代码搜索列表和COUNT REPEAT WORDS
/ * **代码为品牌新单词制作新元素

void list_walk(){
/ * ******代码行走清单并收集统计数据
}




这个问题与C语言一样,与Pascal,Basic,Assembly一样

语言等等。

这是一个家庭作业。最简单的,我必须说。而不是询问,想想

什么是链表。如果你不理解事情,请画出它,除非它们是可视化的。如果你不知道链接列表是什么,请阅读你的书,

讲义,问你的老师,或搜索互联网,但这个我

相信是你能做的事情,无需寻求任何帮助。


Alex


Foodbank写道:< blockquote class =post_quotes>

我必须编写一个程序,它将使用链接列表来打印单个单词,总单词和最常用单词的数量。
文本文件。除了
链接列表之外,我已经完成了相当多的工作。我没有粘贴我的代码告诉机器什么是
字,它工作正常,没有它就会更容易阅读。
以下是代码:
<从这里到下一节的代码很好,我不需要帮助
**** //
#include< stdio.h>
#include< string.h>
#include< stdlib.h>
struct list_elem {
char * word;
int count;
struct list_elem *下一个;
};

struct list_elem * head; / *头指针最初为NULL * /


我会使用更明确的名称

(例如word_head)将其声明为main,然后传递给它作为参数。

// **************************
// **** *******这里及以下的帮助
void add_to_list(char * word_buff){
/ * *代码搜索列表和重复单词
/ * **代码制作品牌新词的新元素


因此,请尝试编写代码,我们将帮助您解决任何特定问题

C编码。我确定你的导师已经解释了链接

列表给你合适的阅读资料。我们尽量避免实际为人们做功课。$ / b
void list_walk(){
/ * ******代码行走列表和收集统计数据


您可能需要一些机制来返回统计数据。

}

非常感谢任何帮助。




尽最大努力。让我们做你的功课不会帮助你学习b
。如果你甚至不能开始那么你真的需要和你的导师讨论它,因为很明显这堂课不适合你。

-

Flash Gordon

生活在有趣的时代。

虽然我的电子邮件地址说垃圾邮件,但它是真实的,我读了它。


大家好,我已经阅读了更多关于链接列表的内容,并且更好地了解了它们现在的情况。我已经添加了一些代码,请你查一下

并可能帮助我找不到什么?


谢谢,
詹姆斯


PS这不是作业,我是自学C,以便改变

职位(比我目前的位置更多的编程方式)。我在一个方面猜测它是功课,但这是为了我自己的利益,而不是为了一个

等级。我非常感谢到目前为止的输入。

#include< stdio.h>

#include< string.h>

#include< stdlib.h>

struct list_elem {

char * word;

int count;

struct list_elem * next;

};


struct list_elem * head;


int get_word(char *) ;

void add_to_list(char *);

void list_walk(void);


int unique_words,total_words;

struct list_elem * most_frequent_elem;


main(){

char word_buff [100];

while( get_word(word_buff))

add_to_list(word_buff);

list_walk();

printf("有%d个唯一字出来的%d总字数\ n",

unique_words,total_words);

printf("最常用字是<%s>使用%d次\\ \\ n",

most_frequent_elem-> word,most_frequent_elem-> count);

}


void add_to_list(char * word_buff){


/ * *****部分搜索链接列表并计算任何数量

重复的单词**** //

//我的开始,不确定是否正确

count = malloc(strlen(word(buff)+1));


/ * *****为品牌新词制作新元素***** /


//我有什么关系FAR

sizeof(struct list_elem);

malloc(sizeof(list_elem));

}


void list_walk(){

/ * ******代码可以列出并收集统计数据***** * /


struct list_elem * lp; int n = 0;

for(lp = head; lp!= NULL; lp = lp-> next)

n ++;

}


//代码不需要修改,我从一个老程序中使用它来告诉编译器什么是字体

#include< ctype.h>

/ *保留此例程,因为它是* /

int get_word(char * s){

int c;

do {

c = getchar();

if(c == EOF)

返回(0);

} while(!isalpha(c)&&!isdigit(c));

do {

if(isupper(c))

c = tolower(c);

* s ++ = c;

c = getchar() ;

} while(isalpha(c)|| isdigit(c));

* s = 0;

return(1);

}


非常感谢任何帮助。


谢谢,

詹姆斯


Hi,

I have to write a program that will use linked lists to print the
number of unique words, total words, and the most frequent word from a
text file. I''ve gotten a decent amount of it done except for the
linked lists. I did not paste my code that tells the machine what a
word is, it works fine and it''ll be easier to read that way without it.
Below is the code:

//****code from here to next section is good, I don''t need help
there****//
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct list_elem {
char *word;
int count;
struct list_elem *next;
};

struct list_elem *head; /* the head pointer is initially NULL */

int get_word(char *);
void add_to_list(char *);
void list_walk(void);

int unique_words, total_words;
struct list_elem *most_frequent_elem;

main() {
char word_buff[100];
while(get_word(word_buff))
add_to_list(word_buff);
list_walk();
printf("there are %d unique words out of %d total words\n",
unique_words, total_words);
printf("the most frequent word is <%s> which used %d times\n",
most_frequent_elem->word, most_frequent_elem->count);
}
//**************************
//***********help here and below
void add_to_list(char *word_buff) {
/* *CODE TO SEARCH THE LIST AND COUNT REPEAT WORDS
/* ** CODE TO MAKE NEW ELEMENTS FOR BRAND NEW WORDS
void list_walk() {
/* ****** CODE TO WALK THE LIST AND GATHER THE STATS
}

Any help is greatly appreciated.

Thanks,
James

解决方案

"Foodbank" <v8********@yahoo.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...

I have to write a program that will use linked lists to print the
number of unique words, total words, and the most frequent word from a
text file. .... //***********help here and below
void add_to_list(char *word_buff) {
/* *CODE TO SEARCH THE LIST AND COUNT REPEAT WORDS
/* ** CODE TO MAKE NEW ELEMENTS FOR BRAND NEW WORDS
void list_walk() {
/* ****** CODE TO WALK THE LIST AND GATHER THE STATS
}



This problem has as much to do with C as with Pascal, Basic, Assembly
language, etc etc.
It''s a homework. The simplest, I must say. Instead of asking, think over
what is a linked list. Draw it if you don''t understand things unless they''re
visualized. If you have no idea what a linked list is, read your book(s),
lecture note(s), ask your teacher, or search the internet, but this I
believe is something you are able to do w/o asking for any help.

Alex


Foodbank wrote:

Hi,

I have to write a program that will use linked lists to print the
number of unique words, total words, and the most frequent word from a
text file. I''ve gotten a decent amount of it done except for the
linked lists. I did not paste my code that tells the machine what a
word is, it works fine and it''ll be easier to read that way without it.
Below is the code:

//****code from here to next section is good, I don''t need help
there****//
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct list_elem {
char *word;
int count;
struct list_elem *next;
};

struct list_elem *head; /* the head pointer is initially NULL */
I would have declared the head within main using a more explicit name
such as word_head and then passed it as a parameter.
//**************************
//***********help here and below
void add_to_list(char *word_buff) {
/* *CODE TO SEARCH THE LIST AND COUNT REPEAT WORDS
/* ** CODE TO MAKE NEW ELEMENTS FOR BRAND NEW WORDS
So try writing the code and we will help you with any specific problems
in C coding you have. I''m sure your tutor has either explained linked
lists of given you suitable reference material to read. We try to avoid
actually doing peoples homework for them.
void list_walk() {
/* ****** CODE TO WALK THE LIST AND GATHER THE STATS
You probably need some mechanism for returning the stats.
}

Any help is greatly appreciated.



Make your best effort. Getting us to do your homework won''t help you to
learn. If you can''t even start then you really need to discuss it with
your tutor since obviously the class is not working for you.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.


Hi guys, I''ve read more about linked lists and have a better idea of
what they are now. I''ve added some code, could you please check it out
and possibly help me with what''s missing?

Thanks,
James

PS This isn''t homework, I''m self-teaching myself C in order to change
job positions (more programming oriented than my current position). I
guess in one regard it is homework, but it''s for my own good, not for a
grade. I do appreciate the input up to this point.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct list_elem {
char *word;
int count;
struct list_elem *next;
};

struct list_elem *head;

int get_word(char *);
void add_to_list(char *);
void list_walk(void);

int unique_words, total_words;
struct list_elem *most_frequent_elem;

main() {
char word_buff[100];
while(get_word(word_buff))
add_to_list(word_buff);
list_walk();
printf("there are %d unique words out of %d total words\n",
unique_words, total_words);
printf("the most frequent word is <%s> which used %d times\n",
most_frequent_elem->word, most_frequent_elem->count);
}

void add_to_list(char *word_buff) {

/* ***** SECTION TO SEARCH THE LINKED LIST AND COUNT ANY
REPEATED WORDS****//
//MY MEASLY START, NOT SURE IF CORRECT
count=malloc(strlen(word(buff)+1));

/* ***** MAKE NEW ELEMENTS FOR BRAND NEW WORDS *****/

//WHAT I''VE GOTTEN SO FAR
sizeof(struct list_elem);
malloc(sizeof(list_elem));
}

void list_walk() {
/* ****** CODE TO WALK THE LIST AND GATHER THE STATS ***** */

struct list_elem *lp; int n=0;
for(lp=head; lp!=NULL; lp=lp->next)
n++;
}

//CODE DOESN''T NEED MODIFIED, I USED IT FROM AN OLD PROGRAM THAT TELLS
THE COMPILER WHAT A WORD IS
#include <ctype.h>
/* Leave this routine EXACTLY as it stands */
int get_word(char *s) {
int c;
do {
c = getchar();
if(c == EOF)
return(0);
} while(!isalpha(c) && !isdigit(c));
do {
if(isupper(c))
c = tolower(c);
*s++ = c;
c = getchar();
} while(isalpha(c) || isdigit(c));
*s = 0;
return(1);
}

Any help is greatly appreciated.

Thanks,
James


这篇关于链接列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆