Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
15 views2 pages

String RLE Pseudocode

The document describes a method for compressing a string using Run Length Encoding (RLE). It outlines a process to count consecutive characters in the input string and output the character followed by its count. The example provided compresses the string 'AAAAGGGSWWWWWWJ' to 'A4G3S1W6J1'.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

String RLE Pseudocode

The document describes a method for compressing a string using Run Length Encoding (RLE). It outlines a process to count consecutive characters in the input string and output the character followed by its count. The example provided compresses the string 'AAAAGGGSWWWWWWJ' to 'A4G3S1W6J1'.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

User input a string

e.g. STR = “AAAAGGGSWWWWWWJ”


Apply RLE and print the compressed string, “A4G3S1W6J1”

DECLARE Str : STRING


DECLARE Ch1, Ch2 : CHAR
DECLARE Counter : INTEGER
DECLARE Continuous : BOOL

OUTPUT “Please enter String to compress.”


INPUT Str

Repeated  1

For C  1 TO Length(Str) // C is Counter


Ch1  MID(Str, Counter, 1)
Ch2  MID(Str, Counter+1, 1)
IF Ch1 = Ch2 THEN
Repeated  Repeated + 1
ELSE
OUTPUT Ch1 & Repeated // Print ch and its count on
same line
Repeated  1 // Reset C for the next ch
sequence
ENDIF
NEXT Counter

// Print the last character and its count on the same line
OUTPUT MID(Str, Length(Str), 1) & Repeated

You might also like