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
18 changes: 18 additions & 0 deletions ASD_Task_2.depend
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,21 @@
"list.h"
"operation.h"

1581162842 source:d:\github\asd_task_2\main.cpp
<iostream>
"list.h"
"operation.h"

1581158381 d:\github\asd_task_2\list.h
<iostream>

1581151762 d:\github\asd_task_2\operation.h
"list.h"

1581163057 source:d:\github\asd_task_2\operation.cpp
"list.h"
"operation.h"

1581163067 source:d:\github\asd_task_2\list.cpp
"list.h"

3 changes: 1 addition & 2 deletions Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int main() {
//==================================================
// TEST INSERT AFTER
P = findElm(L, 6);
insertLast(L, allocate(5));
insertAfter(L,P, allocate(5));
printInfo(L);
cout<<"output should be: 8, 3, 6, 5, 4, 2,"<<endl;

Expand Down Expand Up @@ -95,7 +95,6 @@ int main() {
insert_sorted(L, 5);
printInfo(L);
cout<<"output should be: 1, 3, 5, 8,"<<endl;

//==================================================
cout<<"CONGRATULATION, YOU'VE COMPLETED TASK 2 2019"<<endl;
return 0;
Expand Down
Binary file added bin/Debug/ASD_Task_2.exe
Binary file not shown.
127 changes: 76 additions & 51 deletions list.cpp
Original file line number Diff line number Diff line change
@@ -1,144 +1,169 @@
#include "list.h"

void createList(List &L) {
void createList(List &L)
{
/**
* FS : set first(L) with Null
*/
//-------------your code here-------------
cout<<"your code here"<<endl;


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

address allocate(infotype x) {
address allocate(infotype x)
{
/**
* FS : return new list element with info = x and next element is Null
*/

address P = NULL;
//-------------your code here-------------
cout<<"your code here"<<endl;


P = new elmlist ;
info(P) = x ;
next(P) = NULL ;
//----------------------------------------
return P;
}

void deallocate(address &P) {
void deallocate(address &P)
{
/**
* FS : delete element pointed by P
*/
//-------------your code here-------------
cout<<"your code here"<<endl;


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

void insertFirst(List &L, address P) {
void insertFirst(List &L, address P)
{
/**
* IS : List L may be empty
* FS : element pointed by P became the first element in List L
*/
//-------------your code here-------------
cout<<"your code here"<<endl;



next(P) = first(L) ;
first(L) = P ;
//----------------------------------------
}

void insertLast(List &L, address P) {
void insertLast(List &L, address P)
{
/**
* IS : List L may be empty
* FS : element pointed by P became the last element in List L
*/
//-------------your code here-------------
cout<<"your code here"<<endl;


address Q ;
Q = first(L) ;
while(next(Q) != NULL)
{
Q = next(Q) ;
}
next(Q) = P ;
//----------------------------------------
}

address findElm(List L, infotype x) {
address findElm(List L, infotype x)
{
/**
* IS : List L may be empty
* FS : returns element with info.ID = x.ID,
return Null if such ID is not found
*/

address P;
address P ;
//-------------your code here-------------
cout<<"your code here"<<endl;


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

void deleteFirst(List &L, address &P) {
void deleteFirst(List &L, address &P)
{
/**
* IS : List L may be empty
* FS : first element in List L is removed and is pointed by P
*/
//-------------your code here-------------
cout<<"your code here"<<endl;



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

void deleteLast(List &L, address &P) {
void deleteLast(List &L, address &P)
{
/**
* IS : List L may be empty
* FS : last element in List L is removed and is pointed by P
*/
//-------------your code here-------------
cout<<"your code here"<<endl;



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

void printInfo(List L) {
void printInfo(List L)
{
/**
* FS : view info of all element inside List L,
* call the view_data function from my_data.h to print the info
*/
//-------------your code here-------------
cout<<"your code here"<<endl;


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


void insertAfter(List &L, address Prec, address P) {
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-------------
cout<<"your code here"<<endl;

next(P) = next(Prec) ;
next(Prec) = P ;
//----------------------------------------

}
void deleteAfter(List &L, address Prec, address &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-------------
cout<<"your code here"<<endl;


P = next(Prec) ;
next(Prec) = next(P) ;
next(P) = NULL ;
//----------------------------------------
}

13 changes: 8 additions & 5 deletions list.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ using namespace std;
typedef int infotype;
typedef struct elmlist *address;

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


infotype info ;
address next ;
//----------------------------------------

};

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

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

Expand Down
Binary file added obj/Debug/Main.o
Binary file not shown.
Binary file modified obj/Debug/list.o
Binary file not shown.
Binary file modified obj/Debug/operation.o
Binary file not shown.
36 changes: 31 additions & 5 deletions operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#include "operation.h"


void insert_sorted(List &L, infotype x) {
void insert_sorted(List &L, infotype x)
{
/**
* IS : List may be empty
* PR : insert an infotype x into an already sorted List L
Expand All @@ -11,10 +12,35 @@ void insert_sorted(List &L, infotype x) {
* allocate new element only if the conditions are met
* FS : elements in List L sorted in ascending order, x is inside List L
*/

//-------------your code here-------------
cout<<"your code here"<<endl;


address Q,P ;
P = allocate(x) ;
if (first(L) == NULL)
{
insertFirst(L,P) ;
}
else
{
Q = first(L) ;
while ((next(Q) != NULL) && (x>info(Q)))
{
Q = next(Q) ;
}
if (info(Q) != x)
{
if (x > info(Q))
{
insertLast(L,P) ;
}
else if (x < info(Q))
{
insertFirst(L,P) ;
}
else
{
insertAfter(L,Q,P) ;
}
}
//----------------------------------------
}
}