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
28 changes: 28 additions & 0 deletions ASD_Task_3.depend
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,31 @@
"operation.h"
"my_data.h"

1582384766 source:c:\users\user\documents\github\asd_task_3\list.cpp
"list.h"
"my_data.h"

1582376618 c:\users\user\documents\github\asd_task_3\list.h
<iostream>
"my_data.h"

1582376490 c:\users\user\documents\github\asd_task_3\my_data.h
<iostream>

1582389589 source:c:\users\user\documents\github\asd_task_3\operation.cpp
"list.h"
"operation.h"
"my_data.h"

1582375756 c:\users\user\documents\github\asd_task_3\operation.h
"list.h"

1582390159 source:c:\users\user\documents\github\asd_task_3\main.cpp
<iostream>
"list.h"
"operation.h"
"my_data.h"

1582390220 source:c:\users\user\documents\github\asd_task_3\my_data.cpp
"my_data.h"

Binary file added bin/Debug/ASD_Task_3.exe
Binary file not shown.
109 changes: 72 additions & 37 deletions list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ void createList(List &L) {
* FS : set first(L) and last(L) with Null
*/
//-------------your code here-------------
your code here


first(L) = NULL;
last(L) = NULL;
//----------------------------------------
}

Expand All @@ -19,9 +18,13 @@ address allocate(infotype x) {

address P;
//-------------your code here-------------
your code here


P = new elmlist;
info(P).ID = x.ID;
info(P).name = x.name;
info(P).rank = x.rank;
info(P).score = x.score;
next(P) = NULL;
prev(P) = NULL;
//----------------------------------------
return P;
}
Expand All @@ -31,9 +34,7 @@ void deallocate(address &P) {
* FS : delete element pointed by P
*/
//-------------your code here-------------
your code here


delete P;
//----------------------------------------
}

Expand All @@ -43,9 +44,14 @@ void insertFirst(List &L, address P) {
* FS : element pointed by P became the first element in List L
*/
//-------------your code here-------------
your code here


if(first(L) == NULL && last(L) == NULL){
first(L) = P;
last(L) = P;
} else {
next(P) = first(L);
prev(first(L)) = P;
first(L) = P;
}
//----------------------------------------
}

Expand All @@ -55,9 +61,13 @@ void insertLast(List &L, address P) {
* FS : element pointed by P became the last element in List L
*/
//-------------your code here-------------
your code here


if(first(L) == NULL && last(L) == NULL){
insertFirst(L, P);
} else {
prev(P) = last(L);
next(last(L)) = P;
last(L) = P;
}
//----------------------------------------
}

Expand All @@ -68,11 +78,11 @@ address findElm(List L, infotype x) {
return Null if such ID is not found
*/

address P;
address P = first(L);
//-------------your code here-------------
your code here


if(P != NULL && info(P).ID == x.ID){
P = next(P);
}
//----------------------------------------
return P;
}
Expand All @@ -83,10 +93,16 @@ void deleteFirst(List &L, address &P) {
* FS : first element in List L is removed and is pointed by P
*/
//-------------your code here-------------
your code here



if(first(L) == last(L)){
P = first(L);
first(L) = NULL;
last(L) = NULL;
} else {
P = first(L);
first(L) = next(P);
next(P) = NULL;
prev(first(L)) = NULL;
}
//----------------------------------------
}

Expand All @@ -96,10 +112,10 @@ void deleteLast(List &L, address &P) {
* FS : last element in List L is removed and is pointed by P
*/
//-------------your code here-------------
your code here



P = last(L);
last(L) = prev(P);
next(last(L)) = NULL;
prev(P) = NULL;
//----------------------------------------
}

Expand All @@ -109,35 +125,54 @@ void printInfo(List L) {
* call the view_data function from my_data.h to print the info
*/
//-------------your code here-------------
your code here


address P = first(L);
while(P != NULL){
cout<<info(P).ID<<", "<<info(P).name<<" ,"<<info(P).rank<<" ,"<<info(P).score;
P = next(P);
}
cout<<endl;
//----------------------------------------
}


void insertAfter(List &L, address Prec, address P) {
/**
* IS : Prec and P is not NULL
* FS : element pointed by P is placed behind the element
* pointed by pointer Prec
*/
//-------------your code here-------------
your code here

if(first(L) == NULL && last(L) == NULL){
insertFirst(L, P);
} else if(Prec == last(L)){
insertLast(L, P);
} else {
prev(P) = Prec;
next(P) = next(Prec);
next(Prec) = P;
prev(next(Prec)) = P;
}
//----------------------------------------

}

void deleteAfter(List &L, address Prec, address &P) {
/**
* IS : Prec is not NULL
* FS : element which was before behind an element pointed by Prec
* is removed and pointed by pointer P
*/
//-------------your code here-------------
your code here


if(first(L) == last(L)){
first(L) = NULL;
last(L) = NULL;
} else if(Prec == last(L)){
deleteLast(L, P);
} else {
P = next(Prec);
next(Prec) = next(P);
prev(next(P)) = Prec;
prev(P) = NULL;
next(P) = NULL;
}
//----------------------------------------
}

15 changes: 8 additions & 7 deletions list.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ using namespace std;
* prev : address
* >
*
* Type List : <
* first : address
* last : address
* Type List : <
* first : address
* last : address
* >
*
**/
Expand All @@ -37,14 +37,16 @@ typedef struct elmlist *address;

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

infotype info;
address next;
address prev;
//----------------------------------------
};

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


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

Expand All @@ -67,5 +69,4 @@ void deleteAfter(List&L, address Prec, address &P);
address findElm(List L, infotype x);
void printInfo(List L);


#endif // LIST_H_INCLUDED
46 changes: 44 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,52 @@ void mainMenu() {
case 1:
X = create_data();
P = allocate(X);
insertFirst(L,P)
if(findElm(L, info(P)) == NULL){
insertFirst(L,P);
}
break;
case 2:
printInfo(L);
break;
case 3:
cout<<"ID that you want to know: ";
cin>>X.ID;
P = findElm(L, X);
if(P != NULL){
view_data(info(P));
} else {
cout<<"Data doesn't exist"<<endl;
}
break;
case 4:
cout<<"ID you want to edit: ";
cin>>X.ID;
P = findElm(L, X);
if(P != NULL) {
edit_data(info(P));
} else {
cout<<"Data doesn't exist"<<endl;
}
break;
case 5:
cout<<"ID you want to delete: ";
cin>>X.ID;
if(findElm(L, X) != NULL){
deletebyID(L, X.ID);
} else {
cout<<"Data doesn't exist"<<endl;
}
break;
case 6:
savePassedMember(L, L_passed);
break;
case 7:
printInfo(L_passed);
break;
}
if(choice == 0) {
break;
}
} while(true);

//----------------------------------------
}
41 changes: 24 additions & 17 deletions my_data.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#include "my_data.h"

/**
Expand All @@ -15,11 +15,14 @@ mytype create_data() {
mytype d;
// ===========================
// YOUR CODE HERE
your code here




cout<<"Your ID: ";
cin>>d.ID;
cout<<"Your name: ";
cin>>d.name;
cout<<"Your rank: ";
cin>>d.rank;
cout<<"Your score: ";
cin>>d.score;
// ===========================
return d;
}
Expand All @@ -32,15 +35,15 @@ void view_data(mytype d) {

// ===========================
// YOUR CODE HERE
your code here




cout<<"=============================="<<endl;
cout<<"Your ID: "<<d.ID<<endl;
cout<<"Your name: "<<d.name<<endl;
cout<<"Your rank: "<<d.rank<<endl;
cout<<"Your score: "<<d.score<<endl;
cout<<"=============================="<<endl;
// ===========================
}


void edit_data(mytype &d) {
/**
* TODO: edit the value of data d,
Expand All @@ -50,11 +53,15 @@ void edit_data(mytype &d) {

// ===========================
// YOUR CODE HERE
your code here




cout<<"Your New name: ";
cin>>d.name;
cout<<endl;
cout<<"Your New rank: ";
cin>>d.rank;
cout<<endl;
cout<<"Your New score: ";
cin>>d.score;
cout<<endl;
// ===========================
}

Loading