-
Sort Characters in File
File content :
a
x
z
u
e
f
g
h
k
p
r
o
p
q
r
s
k
h
g
e
l
e
t
read the program up to the last character of the character string and use the program to find the longest consecutive character sequence in alphabetical order
sample character string : x,y,z or e,f,g,h etc.
I just could not make the order, please help
-
So what's your latest effort?
Saying "you tried" and hoping someone will just post a working answer just isn't how this works.
I mean, could you tell if 'ab' is a sequence and 'ac' isn't?
-
stack structure and read from file. for example ; afgbecwfgh ranking : abc , efgh , w
-
Code:
#include <string.h>
#include <stdlib.h>
#define MAXLENGTH 30
typedef struct node {
char word[MAXLENGTH];
}DATA;
typedef struct stack {
DATA data[MAXLENGTH];
int top;
}Stack;
void write(FILE *filee,Stack* st) {
while(!feof(filee)) {
st->top++;
fgets(st->data[st->top].harf,MAXLENGTH,filee);
//printf("%s",st->data[st->top].word);
}
}
void read(Stack* st) {
FILE *filee;
filee=fopen("example.txt","r");
write(filee,st);
}
int main() {
int i;
Stack st;
st.top=-1;
read(&st);
for(i=0;i<=st.top;i++) {
printf("%s\n",st.data.word);
}
}
-
Pop two characters from your stack and see if they're sequential... if they are, you have a sequence of 2, and now you can build the sequence by popping elements.
Once you pop an element that is not in sequence, print the old sequence and it's length. Keep the current element as the start of a new sequence.
Once you can do that I think you'll figure out how to remember which one is the longest you've found, maybe by using a spare stack.
-
Why is the title of this thread "sort"? Sorting is not required at all
-
I don't understand , Please tell me by code