Hi
So I am pretty new with C, but I know a little.. I have been here before and had great help from you guys so I thought I would try it again.
I need to create code for a Sorted Linked List that follow these primitives;
create: -> list
insert: element -> list -> list
raises DuplicateElement
delete: element -> list -> list
raises ElementNotFound
find: element -> list -> Boolean
isEmpty: list -> Boolean
I've worked on some procedural code in class for a list search (find) that looks like this;
List-Search(L, k)
x <-- head[L]
while x =/= NIL and key[x] =/= k
do x <-- next[x]
return x
insert's procedural code looks like this;
List-Insert(L, x)
next[x] <-- head[L]
if head[L] =/= NIL
then prev[head[L]] <-- x
head[L] <-- x
prev[x] <-- NIL
delete's procedural code came out like this;
List-Delete(L, x)
if prev[x] =/= NIL
then next[prev[x]] <-- next[x]
else head[L] <-- next[x]
if next[x] =/= NIL
then prev[next[x]] <-- prev[x]
The areas I am struggling with.. is how to work with the raising of the duplicate element and the missing element, where to place them within the code, and then tying it all into one consistent stream of code.
Also, I am probably wrong, but I figure for the last primitive of isEmpty, you would just write that if your initial search of the List returns NIL, then isEmpty is initiated.
Feel free to ridicule me or help me, any attention is appreciated, I just think I need a little direction and I will see what I can do from there Thanks!!