Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7640019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:34:20+00:00 2026-05-31T08:34:20+00:00

I am pretty green at programming and I’ve to bring assignment tomorrow. It is

  • 0

I am pretty “green” at programming and I’ve to bring assignment tomorrow. It is almost complete but there is a slight problem. I cannot remove the first element and if after trying to delete first element I input
a new one in its place mmm…. lets just say I input infinitely many of them instead. I cant seem to find what is the problem. Thanks in advance

program dvipsar;

type duomenys = integer;
     sarasas = ^elementas;
    elementas = record
       info: duomenys;
       anks: sarasas;
       tolsn: sarasas
     end;


procedure sukurtiTuscia(var s: sarasas);   {creates empty list}
begin
  s := nil
end;

function tuscias(s: sarasas): boolean;   {checks if list is empty}
begin
  tuscias := s = nil
end;

function elmSk(s: sarasas): integer;      {counts elements}
  var kiek: integer;
begin
  kiek := 0;
  while s <> nil do
  begin
    kiek := kiek + 1;
    s := s^.tolsn
  end;
  elmSk := kiek
end;

function gautiRodN(s: sarasas; n:integer): sarasas;     {Arrow to n-th element}
  var i: integer;
begin
  i := 1;
  while (s <> nil) and (i<n) do
  begin
    i := i + 1;
    s := s^.tolsn
  end;
  if i = n then gautiRodN := s
  else gautiRodN := nil
end;

function gautiN(s: sarasas; n:integer): duomenys;         {gets n-th element data}
  var elem: sarasas;
begin
  elem := gautiRodN(s,n);
  if elem <> nil then gautiN := elem^.info
end;

procedure iterptiPries(s:sarasas; n: integer; duom: duomenys);       {adds new element before n-th element}
  var nElem: sarasas;
      naujas: sarasas;
begin
  nElem := gautiRodN(s,n);
  if nElem <> nil then begin
    new (naujas);
    naujas^.info := duom;
    naujas^.tolsn := nElem;
    naujas^.anks := nElem^.anks;
    if nElem^.anks <> nil then nElem^.anks^.tolsn := naujas;
    nElem^.anks := naujas;
 end
end;

procedure panaikintiN(s: sarasas; n: integer);         {removes element from n-th place}
  var nElem: sarasas;
begin
  nElem := gautiRodN(s,n);
  if nElem <> nil then begin
    if nElem^.anks <> nil then nElem^.anks^.tolsn := nElem^.tolsn;
    if nElem^.tolsn <> nil then nElem^.tolsn^.anks := nElem^.anks;
    dispose(nElem);
  end;
end;

function rasti(s: sarasas; duom: duomenys): sarasas;       {finds element}
begin
  while (s <> nil) and (s^.info <> duom) do s := s^.tolsn;
  rasti := s
end;

procedure spausdinti(s: sarasas);                {prints list}
begin
  while (s <> nil) do begin
    write(s^.info,' ');
    s := s^.tolsn
  end;
  writeln
end;

procedure panaikintiP(var s: sarasas);   {removes first element}
  var pirmas: sarasas;
begin
  pirmas := s;
  s := s^.tolsn;
  dispose (pirmas)
end;

procedure panaikinti(var s: sarasas);                     {deletes list}
begin
  while s <> nil do panaikintiP(s)
end;


procedure prideti(var s: sarasas; duom: duomenys);      {add element at the end of the list}
  var kiek: integer;
      paskutinis,naujas: sarasas;
begin
  kiek := elmSk(s);
  paskutinis := gautiRodN(s,kiek);
  new(naujas);
  naujas^.info := duom;
  naujas^.tolsn := nil;
  naujas^.anks := paskutinis;
  if paskutinis <> nil then paskutinis^.tolsn := naujas
  else s := naujas
end;

procedure menu;
begin
  writeln;
  writeln;
  writeln ('1 Creat a list');
  writeln ('2 Count the elements');
  writeln ('3 Check if list is empty');
  writeln ('4 Print an element');
  writeln ('5 Print the list');
  writeln ('6 Remove an element')
  writeln ('7 Add an element');
  writeln ('8 Search in the list');
  writeln;
  writeln ('0 End');
  writeln;
  writeln;

end;
var s: sarasas;
    i,j: integer;
    t: sarasas;
    c: char;
    veiksmas: integer;
begin
  sukurtiTuscia(s);
  repeat
    menu;
    write('Input action number : ');
    readln(veiksmas);
    case veiksmas of
      1:
        repeat 
          write('input a number which you want to add to the list: ');
          readln(i);
          prideti(s,i);
          write('Add new number? (t/n)? ');
          read(c);
        until (c='N') or (c='n');
      2: writeln ('List is not empty: ',elmSk(s));
      3: if tuscias(s) then writeln ('List is empty')
                       else writeln ('List is not empty');
      4: begin
        write ('Which element to print?: ');
        readln(i);
        writeln(i,'-th list element?: ',gautiN(s,i));
      end;
      5: spausdinti(s);
      6: begin
        write ('which element to remove?: ');
        readln(i);
        panaikintiN(s,i);
      end;
      7:begin
        write ('What to add to the list?: ');
        readln(i);
        write ('Before which element?: ');
        readln(j);
        iterptiPries(s,j,i);
      end;
      8: begin
        write ('What element to look for?: ');
        readln(i);
        t := rasti(s,i);
        if t <> nil then writeln (i, ' exists in the list')
                    else writeln (i, ' does not exists in the list');
      end;
      0: writeln ('Ending');
    else writeln('Incorrect action');
    end;
  until veiksmas = 0;
  panaikinti(s);                    {deletes list}
end.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:34:21+00:00Added an answer on May 31, 2026 at 8:34 am

    http://en.wikipedia.org/wiki/Doubly_linked_list#Removing_a_node

    Removal of a node is easier than insertion, but requires special handling if the node to be removed is the firstNode or lastNode:

     function remove(List list, Node node)
       if node.prev == null
           list.firstNode := node.next
       else
           node.prev.next := node.next
       if node.next == null
           list.lastNode := node.prev
       else
           node.next.prev := node.prev
       destroy node
    

    One subtle consequence of the above procedure is that deleting the last node of a list sets both firstNode and lastNode to null, and so it handles removing the last node from a one-element list correctly.

    Notice that we also don’t need separate “removeBefore” or “removeAfter” methods, because in a doubly linked list we can just use “remove(node.prev)” or “remove(node.next)” where these are valid.

    This also assumes that the node being removed is guaranteed to exist.

    If the node does not exist in this list, then some error handling would be required.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty green still when it comes to web programming, I've spent most of
I am pretty green with coding in Ruby but am trying to pull an
I am still pretty green when it comes to web development and javascript/jQuery programming,
This is probably pretty stupid, but I'm still green to LDAP. So I hope
While I'm not a complete Ruby/Rails newb, I'm still pretty green and I'm trying
I'm pretty green with web services and WCF, and I'm using Windows integrated authentication
Pretty sure this question counts as blasphemy to most web 2.0 proponents, but I
I'm pretty green to HttpClient and I'm finding the lack of (and or blatantly
I think this is a pretty simple question but I'm having trouble finding the
Pretty green on this. Any ideas why this works: $('.myclass div').append(' <a >HELLO WORLD</a>').click(this.function);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.