File:  [Research Unix] / researchv10no / cmd / cfront / libstring / test7.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:21:35 2018 UTC (8 years, 1 month ago) by root
Branches: belllabs, MAIN
CVS tags: researchv10, HEAD
researchv10 Norman

// list test program.  reverses standard input

#include "String.h"
#include "list.h"

listdeclare(String)

String_list
revrev ( String_list x )
{
	String_list	ans;
	while ( x ) {
		String	temp;
		x.getX(temp);
		String	rtemp;
		while ( temp ) {
			char	c;
			temp.getX(c);
			rtemp.unget(c);
		}
		ans.unget(rtemp);
	}
	return ans;
}

String_list
rev ( String_list x )
{
	String_list	ans;
	while ( x ) {
		String	temp;
		x.getX(temp);
		ans.unget(temp);
	}
	return ans;
}

String_list
revrec ( String_list x )
{
	if ( x ) {
		String	temp;
		x.getX(temp);
		return revrec(x).put(temp);
	} else return x;
}

main()
{
	String_list	slist;
	String	temp;
	while ( cin >> temp)
		slist.put(temp);
	cout << "rev(slist):"  << rev(slist) << "\n";
	cout << "revrec(slist):" << revrec(slist) << "\n";
	cout << "revrev(slist):" << revrev(slist) << "\n";
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.