I 해요 내 처분에 정렬 된 구조의 다음 구현을 제공 :순서가 설정 표기
이;; os-empty an empty set
;; (os-singleton e) produces a set with one element e
;; (os-member s e) produces true if e is a member of s; false otherwise
;; (os-union s t) produces union of s and t in time
;; O(min(|s|,|t|) log max(|s|,|t|)
;; (os-intersection s t) produces intersection of s and t in time
;; O(min(|s|,|t|) log max(|s|,|t|)
;; (os-difference s t) produces difference s \ t in time
;; O(min(|s|,|t|) log max(|s|,|t|)
;; (os-min s) produces the to-min element of s, or to-min-ident
;; running time: O(log |s|)
;; (os-max s) produces the to-max element of s, or to-max-ident
;; running time: O(log |s|)
;; (os-after s e) produces the to-min element of s which is to> than e
;; running time: O(log |s|)
;; (os-before s e) produces the to-max element of s which is to< than e
;; running time: O(log |s|)
;; (os-op) produces the result of applying to-op over all e in s
;; running time: O(1)
이 코드는 다음 파일에서 찾을 수 있습니다 https://www.student.cs.uwaterloo.ca/~cs136/assignments/a8/ordered-set.rkt 및 https://www.student.cs.uwaterloo.ca/~cs136/assignments/a8/total-order.rkt
을 구조는하지 않습니다 그 안에 중복을 허용하십시오. 여기에 내 문제가있다 : 각 개별 정수를 오름차순으로 쓴 다음 공백을 쓴 다음 입력에서 발생하는 횟수를 출력의 별도 라인에 쓴 프로그램을 작성해야합니다. 여기
Sample Input
1
3
2
1
Output for Sample Input
1 2
2 1
3 1
내가있어 무엇 :
;;Prints in ascending order
(define (printer e s)
(cond
[(equal? (to-unhide e) +inf.0) (printf "")]
[else (printf "~a\n" (to-unhide e)) (printer (os-after s e) s)]))
(define (main)
(define x (read))
(cond
[(eof-object? x) (printer (os-min o) o)]
[(os-member o (os-singlton (to-hide x))) ....... <--- What to do?
[else (set! o (os-union (os-singleton (to-hide x)) o)) (main)]))
(main)
내 문제는 X를 기반으로 카운터를 만드는 방법, 그리고 ... 내가 생각 x의 특별한 그 카운터를 만드는 방법입니다 변수를 생성하는 함수를 만드는 것에 관해서 말입니다.하지만 Scheme에서는 이것이 가능하지 않다고 생각합니다. 이 구조를 사용하여 입력이 사용 된 시간을 기억하는 방법에 대한 제안이 있습니까?
나는 질문의 시작 부분에서 제공 한 기능 만 사용할 수 있습니다. – Thatdude1
다음 숫자 1과 2를 하나의 기능으로 결합하십시오. 하지만, 음, 목록에있는 숫자를 읽은 채로 있으면 실행 시간에 부정적인 영향을 미치지 않는다는 것을 알고 있습니다. – soegaard
아직 목록을 사용하고 있습니까? 제공된 구조는 구조에 중복을 추가하지 않습니다. 그래서 내가 왜 x가 이미 o인지 체크하기 위해서'(os-member o (os-singlton (to-hide x)))'행을 열어 놓고 만약 내가 x와 같은 카운터를 더하고 싶다면, 하지만 어떻게 해야할지 모르겠다. – Thatdude1