Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Muhammad sulthon-1301194008-IF 43 05 #273

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
61 changes: 51 additions & 10 deletions list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ void createList(List &L) {
* FS : set first(L) with Null
*/
//-------------your code here-------------
cout<<"your code here"<<endl;

cout<<"your code here"<<endl;
first(L) = NULL;

//----------------------------------------
}
Expand All @@ -19,6 +20,9 @@ address allocate(infotype x) {
address P = NULL;
//-------------your code here-------------
cout<<"your code here"<<endl;
addrees P = new elmlist;
info(P) = x;
next(P) = NULL;


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

P = NULL;

//----------------------------------------
}
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,13 @@ void insertLast(List &L, address P) {
*/
//-------------your code here-------------
cout<<"your code here"<<endl;

P = new elmlist;
Q = first(L);
while (next(next(Q)) != NULL {
Q = next(Q)
}
P = next(Q);
next(Q) = NULL ;

//----------------------------------------
}
Expand All @@ -71,7 +82,9 @@ 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,6 +97,12 @@ 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 +116,13 @@ void deleteLast(List &L, address &P) {
*/
//-------------your code here-------------
cout<<"your code here"<<endl;

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


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


P = address;
p = first(L);
while(P != NULL){
print(info(P));
P = next(P);
//----------------------------------------
cout<<endl;
}
Expand All @@ -126,6 +154,13 @@ void insertAfter(List &L, address Prec, address P) {
//-------------your code here-------------
cout<<"your code here"<<endl;

P = new elmlist;
Q = first(L);
while (info(Q) != prec{
Q = next(Q)
}
next(P) = next(Q)
next(Q) = P
//----------------------------------------

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


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

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

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


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

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

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

Expand Down
29 changes: 28 additions & 1 deletion 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 @@ -14,7 +15,33 @@ void insert_sorted(List &L, infotype x) {

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



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

//----------------------------------------
}