Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions ASD_Task_2.layout
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="operation.cpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="list.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="656" topLine="0" />
<Cursor1 position="663" topLine="27" />
</Cursor>
</File>
<File name="Main.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="837" topLine="23" />
<Cursor1 position="2649" topLine="82" />
</Cursor>
</File>
<File name="list.h" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="list.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="151" topLine="0" />
<Cursor1 position="3424" topLine="146" />
</Cursor>
</File>
<File name="list.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="operation.cpp" open="1" top="1" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="214" topLine="117" />
<Cursor1 position="958" topLine="11" />
</Cursor>
</File>
<File name="operation.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
Expand Down
56 changes: 48 additions & 8 deletions list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ void createList(List &L) {
*/
//-------------your code here-------------
cout<<"your code here"<<endl;
first(L) = NULL;


//----------------------------------------
Expand All @@ -19,7 +20,9 @@ address allocate(infotype x) {
address P = NULL;
//-------------your code here-------------
cout<<"your code here"<<endl;

P = new elmlist;
info(P) = x;
next(P) = NULL;

//----------------------------------------
return P;
Expand All @@ -31,6 +34,7 @@ void deallocate(address &P) {
*/
//-------------your code here-------------
cout<<"your code here"<<endl;
delete(P);


//----------------------------------------
Expand All @@ -43,7 +47,8 @@ void insertFirst(List &L, address P) {
*/
//-------------your code here-------------
cout<<"your code here"<<endl;

next(P) = first(L);
first(L) = P;


//----------------------------------------
Expand All @@ -56,7 +61,16 @@ void insertLast(List &L, address P) {
*/
//-------------your code here-------------
cout<<"your code here"<<endl;

address Q;
Q = first(L);
if (Q == NULL){
first(L) = P;
} else {
while (next(Q) != NULL){
Q = next(Q);
}
next(Q) = P;
}

//----------------------------------------
}
Expand All @@ -71,7 +85,10 @@ address findElm(List L, infotype x) {
address P;
//-------------your code here-------------
cout<<"your code here"<<endl;

P = first(L);
while (P != NULL && info(P) != x){
P = next(P);
}

//----------------------------------------
return P;
Expand All @@ -84,7 +101,11 @@ void deleteFirst(List &L, address &P) {
*/
//-------------your code here-------------
cout<<"your code here"<<endl;

if (first(L) != NULL){
P = first(L);
first(L) = next(P);
next(P) = NULL;
}


//----------------------------------------
Expand All @@ -97,7 +118,17 @@ void deleteLast(List &L, address &P) {
*/
//-------------your code here-------------
cout<<"your code here"<<endl;

address Q;
Q = first(L);
if (next(Q) == NULL){
deleteFirst(L, P);
} else {
while (next(next(Q)) != NULL){
Q = next(Q);
}
P = next(Q);
next(Q) = NULL;
}


//----------------------------------------
Expand All @@ -110,7 +141,12 @@ void printInfo(List L) {
*/
//-------------your code here-------------
cout<<"your code here"<<endl;

address P;
P = first(L);
while (P != NULL){
cout<<info(P)<<", ";
P = next(P);
}

//----------------------------------------
cout<<endl;
Expand All @@ -125,6 +161,8 @@ void insertAfter(List &L, address Prec, address P) {
*/
//-------------your code here-------------
cout<<"your code here"<<endl;
next(P) = next(Prec);
next(Prec) = P;

//----------------------------------------

Expand All @@ -137,7 +175,9 @@ void deleteAfter(List &L, address Prec, address &P) {
*/
//-------------your code here-------------
cout<<"your code here"<<endl;

P = next(Prec);
next(Prec) = next(P);
next(P) = NULL;

//----------------------------------------
}
Expand Down
5 changes: 3 additions & 2 deletions list.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ typedef struct elmlist *address;

struct elmlist{
//------------- your code here -----------

infotype info;
address next;

//----------------------------------------
};

struct List{
//------------- your code here -----------

address first;
//----------------------------------------
};

Expand Down
11 changes: 11 additions & 0 deletions operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ void insert_sorted(List &L, infotype x) {

//-------------your code here-------------
cout<<"your code here"<<endl;
address P, Q;
P = first(L);
if (P == NULL || info(P) > x){
insertFirst(L, allocate(x));
} else if (findElm(L, x) == NULL){
while (P != NULL && info(P) < x){
Q = P;
P = next(P);
}
insertAfter(L, Q, allocate(x));
}


//----------------------------------------
Expand Down