I have to write a code.The program compute random sentences by using singly linked list date structure.The same word cannot be used more than once.
I've already written the some codes which takes the list.
// random_sentence_operator.cpp : Defines the entry point for the console application.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 40
typedef struct SLLTag{
char * data;
struct SLLTag * next;
}SLLNode;
void addNode(SLLNode *cur,char *str);
void displayList(SLLNode *cur);
void randomSentence(SLLNode *cur,char *sentence);
int _tmain(int argc, _TCHAR* argv[])
{
char str[SIZE];
SLLNode *head;
head=(SLLNode *)malloc(sizeof(SLLNode));
head->next=NULL;
head->data="";
printf("Enter the words to add the list:(Press '0' to stop)\n");
while(1)
{
scanf("%s",str);
if(!strcmp(str,"0")==0)
addNode(head,str);
else break;
}
displayList(head);
return 0;
}
void addNode(SLLNode *cur,char *str)
{
while(cur->next != NULL)
cur=cur->next;
cur->next=(SLLNode *)malloc(sizeof(SLLNode));
cur->next->data = (char *)malloc(sizeof(char)*SIZE);
strcpy(cur->next->data,str);
cur->next->next=NULL;
}
void displayList(SLLNode *cur)
{
printf("The words which you added the list are:\n");
while(cur->next!=NULL)
{
printf("%s\n",cur->next->data);
cur=cur->next;
}
}
void randomSentence(SLLNode *cur,char *sentence)
{
}
I take the words with this code.Now,How can i create a random sentece with these words.Need some more ideas.