- #1
TheMathNoob
- 189
- 4
Mod note: Added code tags
1. Homework Statement
in my main I am getting infinite loop iterating over a link list
1. Homework Statement
in my main I am getting infinite loop iterating over a link list
Homework Equations
The Attempt at a Solution
C:
/*
* graph.c
*
* Created on: Oct 8, 2015
* Author: danif
*/
#include <stdio.h>
#include "IntList.h"
int main(void)
{
typedef struct IntListStruct* List;
List l1=IntListCons(3,NULL);
List l2=IntListCons(3,l1);
List l3=IntListCons(4,l2);
List Tester;
Tester=l3;
while(Tester!=NULL)
{
printf("%d\n",Tester->element);
Tester=rest(Tester);
}}/*
* IntList.c
*
* Created on: Oct 8, 2015
* Author: danif
*/
#include "IntList.h"struct IntListStruct* IntListCons(int newb, struct IntListStruct *oldList)
{
struct IntListStruct newL;
newL.element=newb;
newL.pt=oldList;
struct IntListStruct* pnewL= &newL;
return pnewL;
}
int first(struct IntListStruct* L)
{
return L->element;
}
struct IntListStruct* rest(struct IntListStruct* L)
{
return L->pt;
}
Last edited by a moderator: